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

java.io.IOException: Error detected parsing the header on un-archiving. Archive untars fine in BSDTar and JTar

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.18
    • 1.19
    • Archivers

    Description

      Using TarArchiveInputStream to parse this tar archive results in a

      `java.io.IOException: Error detected parsing the header`

      `Caused by: java.lang.IllegalArgumentException: Invalid byte 78 at offset 8 in '00000000NaN{NUL}' len=12`

       

      The `00000000NaN{NUL}` value is indeed found in the tar archive at the point that TarArchiveInputStream finds it and errors, but both BSDTar from a bash shell and JTar from a Java environment handle the archive fine, including the file with the malformed header. My commons-compress code is:

      private static List<File> unTar(final File inputFile, final File outputDir) throws FileNotFoundException, IOException, ArchiveException {
      
        System.out.println(String.format("Untaring %s to dir %s.", inputFile.getAbsolutePath(), outputDir.getAbsolutePath()));
      
        final List<File> untaredFiles = new LinkedList<File>();
        final InputStream is = new FileInputStream(inputFile);
        final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
        TarArchiveEntry entry = null;
          while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
            final File outputFile = new File(outputDir, entry.getName());
            if (entry.isDirectory()) {
              System.out.println(String.format("Attempting to write output directory %s.", outputFile.getAbsolutePath()));
              if (!outputFile.exists()) {
                System.out
                    .println(String.format("Attempting to create output directory %s.", outputFile.getAbsolutePath()));
                if (!outputFile.mkdirs()) {
                  throw new IllegalStateException(
                      String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
                }
              }
            }
            else {
              System.out.println(String.format("Creating output file %s.", outputFile.getAbsolutePath()));
              final OutputStream outputFileStream = new FileOutputStream(outputFile);
              IOUtils.copy(debInputStream, outputFileStream);
              outputFileStream.close();
            }
            untaredFiles.add(outputFile);
          }
      
        debInputStream.close();
      
        return untaredFiles;
      }
      

      compress-bug-POC.tar.gz

      I've attached an archive of my proof-of-concept code that un-archives the problem archive using JTar, then attempts to un-archive it using commons-compress. The problem archive is included. Unfortunately I wasn't involved in the creation of the problem archive, it was downloaded from NPM last year, so I don't have any details about the archival process that caused the malformed header.

      Attachments

        1. compress-bug-POC.tar.gz
          1.54 MB
          Kirk Hardy

        Activity

          People

            Unassigned Unassigned
            cptkrrk Kirk Hardy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: