You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "PJ Fanning (Jira)" <ji...@apache.org> on 2022/04/14 13:42:00 UTC

[jira] [Commented] (XMLBEANS-604) Incorrect Assert in Saver.TextSaver

    [ https://issues.apache.org/jira/browse/XMLBEANS-604?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17522312#comment-17522312 ] 

PJ Fanning commented on XMLBEANS-604:
-------------------------------------

I added a disabled test - r1899853 - [https://github.com/apache/xmlbeans/commit/9edca7dfdede29c0fd9853de127c127681329616]

 

Not really sure what to do about this yet though

> Incorrect Assert in Saver.TextSaver
> -----------------------------------
>
>                 Key: XMLBEANS-604
>                 URL: https://issues.apache.org/jira/browse/XMLBEANS-604
>             Project: XMLBeans
>          Issue Type: Bug
>          Components: XmlObject
>    Affects Versions: Version 5.0.3
>         Environment: Windows 10, JDK 1.8.0_311
>            Reporter: Timon Hertli
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> If the Buffer _buf in org.apache.xmlbeans.impl.store.Saver.TextSaver.write(Writer, int) is completely filled (this happens if the current charsAvailable is a large power of 2, in the example 2^14=16384), the _in index is set to 0 ( = 16384 % 16384) in emit(String). This causes the assertion
>  
> {code:java}
> assert _free == _buf.length - _in;{code}
> to fail (with _free = 0, _buf.length = 16384, _in = 0). The behaviour of the code seems correct, but the assert does not account for the fact that _in can wrap around to 0.
>  
> The following code reproduces the problem (if assertions are enabled):
>  
> {code:java}
> import org.apache.xmlbeans.XmlBeans;
> import org.apache.xmlbeans.XmlObject;
> import java.io.InputStream;
> public class AssertionTest {
>   public static void main(String[] args) throws Exception {
>     System.getProperties().setProperty("line.separator", "\n");
>     String xml = "<test>" + new String(new char[16339]).replace('\0', 'x') + "</test>";
>     XmlObject object = XmlObject.Factory.parse(xml);
>     try (InputStream is = object.newInputStream()) {
>       is.read(new byte[8192], 0, 8192);
>     }
>   }
> }{code}
> with the following stack trace:
>  
>  
> {code:java}
> Exception in thread "main" java.lang.AssertionError
>     at org.apache.xmlbeans.impl.store.Saver$TextSaver.write(Saver.java:1708)
>     at org.apache.xmlbeans.impl.store.Saver$InputStreamSaver.ensure(Saver.java:2344)
>     at org.apache.xmlbeans.impl.store.Saver$InputStreamSaver.access$200(Saver.java:2230)
>     at org.apache.xmlbeans.impl.store.Saver$InputStreamSaver$OutputStreamImpl.read(Saver.java:2389)
>     at org.apache.xmlbeans.impl.store.Saver$InputStreamSaver.lambda$read$0(Saver.java:2328)
>     at org.apache.xmlbeans.impl.store.Saver.syncWrap(Saver.java:2180)
>     at org.apache.xmlbeans.impl.store.Saver.access$000(Saver.java:33)
>     at org.apache.xmlbeans.impl.store.Saver$InputStreamSaver.read(Saver.java:2328)
>     at AssertionTest.main(AssertionTest.java:12){code}
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org