You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Konrad Windszus (JIRA)" <xe...@xml.apache.org> on 2007/10/15 14:49:50 UTC

[jira] Created: (XERCESJ-1275) java.lang.ArrayIndexOutOfBoundsException at org.apache.xerces.impl.XMLEntityScanner.skipSpaces

java.lang.ArrayIndexOutOfBoundsException at org.apache.xerces.impl.XMLEntityScanner.skipSpaces
----------------------------------------------------------------------------------------------

                 Key: XERCESJ-1275
                 URL: https://issues.apache.org/jira/browse/XERCESJ-1275
             Project: Xerces2-J
          Issue Type: Bug
    Affects Versions: 2.7.1, 2.9.1
            Reporter: Konrad Windszus


Under some rare circumstances you get an ArrayIndexOutOfBoundsException in Xerces. This is the case if the Reader you give with the SaxParser.parse-Method returns 0 for the method public int read(char[] cbuf, int off, int len) 
This can lead to that exception.
Apparently Xerces reads in the XML in chunks of 2048 bytes. If the last read(..) call returns 2048 filled bytes, and the following read returns 0 (although it should return -1) this exception occurs. You should prevent this by accepting 0 as valid return of read, although it does not indicate, that the end of file has been reached.
    

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Commented: (XERCESJ-1275) java.lang.ArrayIndexOutOfBoundsException at org.apache.xerces.impl.XMLEntityScanner.skipSpaces

Posted by "Konrad Windszus (JIRA)" <xe...@xml.apache.org>.
    [ https://issues.apache.org/jira/browse/XERCESJ-1275?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12535170 ] 

Konrad Windszus commented on XERCESJ-1275:
------------------------------------------

I think the Javadoc is at least a littlebit misleading here. I found the following paragraph in the Doc of InputStream.read(...) 
...
"Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer. "
...
That shows, that zero is a valid return value, although you could interpret it as allowed only in the case of len equals zero too.

"If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b. "

Nevertheless there is no statement about the return value in Reader.read(). Therefore I would suggest improving the behaviour of Xerces in the case, 0 is returned. It should be very easy to accomplish and shouldn't have any impact on the performance overall.



> java.lang.ArrayIndexOutOfBoundsException at org.apache.xerces.impl.XMLEntityScanner.skipSpaces
> ----------------------------------------------------------------------------------------------
>
>                 Key: XERCESJ-1275
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1275
>             Project: Xerces2-J
>          Issue Type: Bug
>    Affects Versions: 2.7.1, 2.9.1
>            Reporter: Konrad Windszus
>
> Under some rare circumstances you get an ArrayIndexOutOfBoundsException in Xerces. This is the case if the Reader you give with the SaxParser.parse-Method returns 0 for the method public int read(char[] cbuf, int off, int len) 
> This can lead to that exception.
> Apparently Xerces reads in the XML in chunks of 2048 bytes. If the last read(..) call returns 2048 filled bytes, and the following read returns 0 (although it should return -1) this exception occurs. You should prevent this by accepting 0 as valid return of read, although it does not indicate, that the end of file has been reached.
>     

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Resolved: (XERCESJ-1275) java.lang.ArrayIndexOutOfBoundsException at org.apache.xerces.impl.XMLEntityScanner.skipSpaces

Posted by "Michael Glavassevich (JIRA)" <xe...@xml.apache.org>.
     [ https://issues.apache.org/jira/browse/XERCESJ-1275?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Glavassevich resolved XERCESJ-1275.
-------------------------------------------

    Resolution: Duplicate

Duplicate of XERCESJ-1015.

==========================

The Javadoc for Reader.read(char[] cbuf, int off, int len) says:

Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

The Javadoc for InputStream.read(byte[] b, int off, int len) says:

"...

This method blocks until input data is available, end of file is detected, or an exception is thrown. 

If b is null, a NullPointerException is thrown. 

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown. 

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

..."

Zero bytes will only be read if the length specified is zero, otherwise at least one byte will be read. When the length parameter is non-zero a *conforming* InputStream must return at least one byte (or one char in the case of a Reader) or -1 if the end of the stream has been reached. It sounds like the InputStream/Reader you are using is violating this condition and returning 0 instead of -1 at the end of the stream. This is a bug in the InputStream/Reader, not the parser and should be fixed at the source. When the stream is broken the parser shouldn't be guessing what it's trying to tell it.

> java.lang.ArrayIndexOutOfBoundsException at org.apache.xerces.impl.XMLEntityScanner.skipSpaces
> ----------------------------------------------------------------------------------------------
>
>                 Key: XERCESJ-1275
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1275
>             Project: Xerces2-J
>          Issue Type: Bug
>    Affects Versions: 2.7.1, 2.9.1
>            Reporter: Konrad Windszus
>
> Under some rare circumstances you get an ArrayIndexOutOfBoundsException in Xerces. This is the case if the Reader you give with the SaxParser.parse-Method returns 0 for the method public int read(char[] cbuf, int off, int len) 
> This can lead to that exception.
> Apparently Xerces reads in the XML in chunks of 2048 bytes. If the last read(..) call returns 2048 filled bytes, and the following read returns 0 (although it should return -1) this exception occurs. You should prevent this by accepting 0 as valid return of read, although it does not indicate, that the end of file has been reached.
>     

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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