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/09/26 15:29:00 UTC

[jira] [Comment Edited] (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=17420313#comment-17420313 ] 

Gary D. Gregory edited comment on IO-716 at 9/26/21, 3:28 PM:
--------------------------------------------------------------

[~Marcono1234],
I took the keep-it-simple path: The constructor now requires a minimum size of 2 or throws an IllegalArgumentException.
Please verify your use case and close.


was (Author: garydgregory):
I took the keep-it-simple path: The constructor now requires a minimum size of 2 or throws an IllegalArgumentException.


> 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
>             Fix For: 2.12.0
>
>
> {{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)