You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Teemu Lång (JIRA)" <ji...@apache.org> on 2010/12/22 04:14:01 UTC

[jira] Created: (IO-257) BOMInputStream.read(byte[]) can return 0 which it should not

BOMInputStream.read(byte[]) can return 0 which it should not
------------------------------------------------------------

                 Key: IO-257
                 URL: https://issues.apache.org/jira/browse/IO-257
             Project: Commons IO
          Issue Type: Bug
          Components: Streams/Writers
    Affects Versions: 2.0
            Reporter: Teemu Lång
            Priority: Critical


BOMInputStream.read(byte[]) returns 0 when it should return -1.

This is not a valid action (unless buf.length == 0) and can cause problems, e.g. "java.io.IOException: Underlying input stream returned zero bytes - at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:268)"

>From java.io.InputStream.read(byte[]) JavaDocs: "If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b."

Suggested fix, change line 287 of BOMInputStream.java from
        return (secondCount < 0) ? firstCount : firstCount + secondCount;
into
        return (secondCount < 0) ? (firstCount > 0 ? firstCount : -1) : firstCount + secondCount;


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (IO-257) BOMInputStream.read(byte[]) can return 0 which it should not

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IO-257?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12976413#action_12976413 ] 

Niall Pemberton commented on IO-257:
------------------------------------

Commons IO 2.0.1 has been released which resolves this

> BOMInputStream.read(byte[]) can return 0 which it should not
> ------------------------------------------------------------
>
>                 Key: IO-257
>                 URL: https://issues.apache.org/jira/browse/IO-257
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.0
>            Reporter: Teemu Lång
>            Assignee: Niall Pemberton
>            Priority: Critical
>             Fix For: 2.0.1
>
>
> BOMInputStream.read(byte[]) returns 0 when it should return -1.
> This is not a valid action (unless buf.length == 0) and can cause problems, e.g. "java.io.IOException: Underlying input stream returned zero bytes - at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:268)"
> From java.io.InputStream.read(byte[]) JavaDocs: "If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b."
> Suggested fix, change line 287 of BOMInputStream.java from
>         return (secondCount < 0) ? firstCount : firstCount + secondCount;
> into
>         return (secondCount < 0) ? (firstCount > 0 ? firstCount : -1) : firstCount + secondCount;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (IO-257) BOMInputStream.read(byte[]) can return 0 which it should not

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IO-257?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Niall Pemberton resolved IO-257.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 2.1
         Assignee: Niall Pemberton

Thanks for the fix - I have applied the change:

http://svn.apache.org/viewvc?view=revision&revision=1052095

> BOMInputStream.read(byte[]) can return 0 which it should not
> ------------------------------------------------------------
>
>                 Key: IO-257
>                 URL: https://issues.apache.org/jira/browse/IO-257
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.0
>            Reporter: Teemu Lång
>            Assignee: Niall Pemberton
>            Priority: Critical
>             Fix For: 2.1
>
>
> BOMInputStream.read(byte[]) returns 0 when it should return -1.
> This is not a valid action (unless buf.length == 0) and can cause problems, e.g. "java.io.IOException: Underlying input stream returned zero bytes - at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:268)"
> From java.io.InputStream.read(byte[]) JavaDocs: "If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b."
> Suggested fix, change line 287 of BOMInputStream.java from
>         return (secondCount < 0) ? firstCount : firstCount + secondCount;
> into
>         return (secondCount < 0) ? (firstCount > 0 ? firstCount : -1) : firstCount + secondCount;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.