cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Santiago Gala <>
Subject Re: [C2] AIOOBE in XMLByteStreamInterpreter
Date Thu, 31 May 2001 15:37:48 GMT
Klaasen Tom wrote:

> Hi all,
> I had some troubles with the XMLByteStreamInterpreter today. I noticed it
> has recently changed (this morning), but I don't see how this change could
> cause the bug (but then again, I didn't examine it too closely ;) ).
> At intermittent times, I got an ArrayIndexOutOfBoundsException. Applying the
> patch attached solved the problem for me.

The patch is defensive, and needed for the first occurrence of "" in the 
stream. Instead, I would rather modify readChars( int len ) from 
returning a  char[len] null padded for utf size reduction, and instead 
return a char[] containing the exact number of characters read. This 
could be achieved by using a new StringBuffer(len) to append the UTF-8 
decoded characters, and returning it.toCharArray(). I know it is less 
efficient, but it is cleaner code. This would eliminate the need for the 
whole while (really a hack).

The other bug I mentioned I found (in case anybody audits this one) is 
in XMLByteArrayCompiler. It is using 65535 to compare for the maximum 
string length, while it should use 2 << 15 - 1 or 0x7fff (32767, I 
think) as in the other comparison. Also, the first comparison is done 
*before* encoding to utf, so it is mostly useless as the length can 
increase in the encoding process. The second comparison is still wrong. 
It should compare against 2<<15 *excluding* it, as the interpreter does.

It is highly unlikely, but if a String of exactly 2<<15 bytes after 
encoding is processed, somethings weird will happen. It will be written 
to the stream, but later the interpreter will retrieve the first entry 
in the String map instead...

I would recommend also to have these and other constants used abstracted 
out of the code to an Interface, to ensure consistency.

I could fix this, if you want, and send a patch. But I have a lot of 
work, and would only do it if you agree with the concept beforehand.


To unsubscribe, e-mail:
For additional commands, email:

View raw message