java/3426: java.io.InputStreamReader, infinite loop

david-b@pacbell.net david-b@pacbell.net
Tue Jun 26 08:16:00 GMT 2001


>Number:         3426
>Category:       java
>Synopsis:       java.io.InputStreamReader, infinite loop
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 26 08:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     david-b@pacbell.ne
>Release:        gcj 3.0
>Organization:
>Environment:
RedHat 7.0, i686-pc-linux-gnu
>Description:
The for(;;) loop in the second half of java.io.InputStreamReader
will loop infinitely in the following case:

- two bytes left at the end of the buffered stream

- using a multibyte encoding, such as iso-2022-jpase, or
  shift_jis

- the character being read takes more than two bytes

In that case the converter.read() machinery tries to
report ("wcount = 0"?) an incomplete read, but there
seems to be no mechanism in place to

 (a) shift the remaining bytes to the beginning
     of the BufferedInputStream
 (b) read more bytes, so that converter.read()
     can progress

So the for(;;)  inside read() will never terminate,
since each pass only proceeds by zero bytes.
>How-To-Repeat:
Use the SAX/XML test suite at http://xmlconf.sourceforge.net
and reconfigure the GCJ version not to make special cases
for the two biggish (200K) Japanese translations of a draft
of the XML spec (pr-xml-iso-2022-jp, pr-xml-shift_jis).
The GDB work characterized here used the first of those,
I'm assuming the second loop is the same bug.

(You'll need the "java/lib" and "xml" modules from CVS
there.  Sorry I don't have a small test case.)
>Fix:
Note that inside gnu/gcj/convert/natIconv.cc there is a
"FIXME:  what if R == -1 ?" comment which seems like it
is what's being hit here.  Suggested fix there is to
return -1 in that case, and throw an exception in the
#else /* !HAVE_ICONV */ branch using "-1" as some sort
of error, passing the iconv convention up a layer.

Then InputStreamReader.read() does need logic for (a), (b).
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list