Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-717

Infinite loop in ReaderInputStream instead of throwing exception for CodingErrorAction.REPORT

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.8.0
    • 2.12.0
    • Streams/Writers
    • None

    Description

      org.apache.commons.io.input.ReaderInputStream constructed with a CharsetEncoder with CodingErrorAction.REPORT does not throw exceptions when unmappable or malformed input is encountered. And in some cases can even enter infinite loops.

      Example:

      CharsetEncoder encoder = StandardCharsets.UTF_8.newEncoder().onMalformedInput(CodingErrorAction.REPORT);
      try (InputStream in = new ReaderInputStream(new StringReader("\uD800aa"), encoder, 2)) {
          in.read();
      }
      

      The reason for this is that the class does not check CoderResult.isError() and then call CoderResult.throwException().


      It would also be good to improve the documentation of the constructors taking a Charset or charset name to describe that they replace unmappable or malformed input with the default replacement character.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Marcono1234 Marcono1234
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: