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

SeekableInMemoryByteChannel sets position incorrectly if > size

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.19
    • 1.20
    • None
    • None

    Description

      Something we noticed in passing when attempting to use this class as a reference for implementing a new channel class of our own:

      https://github.com/apache/commons-compress/blob/c03704d773dfa0dfc5b2e53b4c198a95d0213ca0/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java#L102

      If the size of the file/channel is 10 and I call truncate(12), the current behaviour is to set the position back to 10.

      The docs of SeekableByteChannel, however, require that this not be done:

      https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/channels/SeekableByteChannel.html#truncate(long)

      If the given size is greater than or equal to the current size then the entity is not modified. In either case, if the current position is greater than the given size then it is set to that size.

      I'm not sure whether this bug means there is a bug in the compression library proper, because anyone using a channel sensibly would not be setting the position past the length anyway, but I thought I would raise the issue regardless, in case that were not the case.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              trejkaz Trejkaz
              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