Commons IO
  1. Commons IO
  2. IO-257

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0.1
    • Component/s: Streams/Writers
    • Labels:
      None

      Description

      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;

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        19h 52m 1 Niall Pemberton 22/Dec/10 23:06
        Resolved Resolved Closed Closed
        322d 19h 3m 1 Henri Yandell 10/Nov/11 18:09
        Henri Yandell made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Workflow jira [ 12540731 ] Default workflow, editable Closed status [ 12601904 ]
        Hide
        Niall Pemberton added a comment -

        Commons IO 2.0.1 has been released which resolves this

        Show
        Niall Pemberton added a comment - Commons IO 2.0.1 has been released which resolves this
        Niall Pemberton made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Niall Pemberton [ niallp ]
        Fix Version/s 2.1 [ 12315445 ]
        Resolution Fixed [ 1 ]
        Hide
        Niall Pemberton added a comment -

        Thanks for the fix - I have applied the change:

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

        Show
        Niall Pemberton added a comment - Thanks for the fix - I have applied the change: http://svn.apache.org/viewvc?view=revision&revision=1052095
        Teemu Lång created issue -

          People

          • Assignee:
            Niall Pemberton
            Reporter:
            Teemu Lång
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development