Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
2.8.0
-
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.