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

ReaderInputStream enter infinite loop for too small buffer sizes

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

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

    Description

      org.apache.commons.io.input.ReaderInputStream enters an infinite loop when it was constructed with a too small buffer size (0 or 1) and one of its reading methods is called.

      Example:

      int bufferSize = 1;
      try (InputStream in = new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, bufferSize)) {
          in.read();
      }
      

      This could be solved by making sure that the buffer size is always >= 2. This should solve this issue because as far as I know all charsets only report UNDERFLOW without encoding any chars if the only char in the buffer is a surrogate.
      However, the saner solution might be to increase the buffer when UNDERFLOW is encountered and no chars from encoderIn have been consumed.


      Similarly for sanety it would be good to throw an AssertionError (or increase the size of encoderOut) if OVERFLOW is returned. I don't think there are any encodings which require more than 128 bytes (used by ReaderInputStream for the output buffer) for encoding a single char or flushing, but would be good to at least handle that case in a saner way than entering an infinite loop anyways.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment