You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2021/02/17 16:20:00 UTC
[jira] [Commented] (IO-716) ReaderInputStream enter infinite loop
for too small buffer sizes
[ https://issues.apache.org/jira/browse/IO-716?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17285948#comment-17285948 ]
Gary D. Gregory commented on IO-716:
------------------------------------
[~Marcono1234]
Thank you for your report.
Feel free to provide a PR on GitHub with tests ;-)
> ReaderInputStream enter infinite loop for too small buffer sizes
> ----------------------------------------------------------------
>
> Key: IO-716
> URL: https://issues.apache.org/jira/browse/IO-716
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.8.0
> Reporter: Marcono1234
> Priority: Major
>
> {{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:
> {code}
> int bufferSize = 1;
> try (InputStream in = new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, bufferSize)) {
> in.read();
> }
> {code}
> 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.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)