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

Multiple retrievals of InputStream for same SevenZFile entry fails

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.20
    • Fix Version/s: 1.21
    • Component/s: None
    • Labels:
      None

      Description

      I was trying out the new random access for the 7z files and have one of our tests failing where we are trying to read the same entry multiple times without closing the archive.

      Reproducing test case (I added this locally to the SevenZFileTest class)

      @Test
      public void retrieveInputStreamForEntryMultipleTimes() throws IOException {
          try (SevenZFile sevenZFile = new SevenZFile(getFile("bla.7z"))) {
              for (SevenZArchiveEntry entry : sevenZFile.getEntries()) {
                  byte[] firstRead = IOUtils.toByteArray(sevenZFile.getInputStream(entry));
                  byte[] secondRead = IOUtils.toByteArray(sevenZFile.getInputStream(entry));
                  assertArrayEquals(firstRead, secondRead);
              }
          }
      }
      

      The Exception thrown is

      java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 2	at org.apache.commons.compress.archivers.sevenz.SevenZFile.buildDecodingStream(SevenZFile.java:1183)
      	at org.apache.commons.compress.archivers.sevenz.SevenZFile.getInputStream(SevenZFile.java:1436)
      	at org.apache.commons.compress.archivers.sevenz.SevenZFileTest.retrieveInputStreamForEntryMultipleTimes(SevenZFileTest.java:688)
      	...
      

      A similar test case for e.g. zip works fine

      @Test
      public void retrieveInputStreamForEntryMultipleTimes() throws IOException {
          try (ZipFile zipFile = new ZipFile(getFile("bla.zip"))) {
              Enumeration<ZipArchiveEntry> entry = zipFile.getEntries();
              while (entry.hasMoreElements()) {
                  ZipArchiveEntry e = entry.nextElement();
                  byte[] firstRead = IOUtils.toByteArray(zipFile.getInputStream(e));
                  byte[] secondRead = IOUtils.toByteArray(zipFile.getInputStream(e));
                  assertArrayEquals(firstRead, secondRead);
              }
          }
      }
      

        Attachments

          Activity

            People

            • Assignee:
              peterlee Peter Lee
              Reporter:
              rschimpf Robin Schimpf
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: