Uploaded image for project: 'Commons Compress'
  1. Commons Compress
  2. COMPRESS-595

IOUtils.readRange(ReadableByteChannel input, int len) reads more than len when input.read() returns < len (ie. there is a partial read)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 1.21
    • 1.22
    • None
    • None

    Description

      When `input.read(b)` returns `readNow` < `len`, then it means
      `input.read(b)` will need to be called again with the same
      buffer, whose `remaining()` is now the old `remaining()` - `readNow`.

      This way the ReadableByteChannel knows how many bytes are to be
      read in subsequent iterations of the `while (read < len)` loop.

      This is currently not the case, because there is a call to rewind()
      which results in a buffer whose remaining() is reset to `len` if
      `readNow` < `len`.

      I suspect the readRange() method has only been used with channels that never do partial reads (such In Memory Byte Channels backed by an array), and hence the problem has not been experienced until now.

       

      Attachments

        1. IOUtilsTest.kt
          1 kB
          NP

        Issue Links

          Activity

            People

              Unassigned Unassigned
              nervy_protozoan NP
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m