You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Akhila Mangipudi (Jira)" <ji...@apache.org> on 2020/04/20 22:55:00 UTC

[jira] [Created] (COMPRESS-511) Decompress tar failed. java.io.IOException: Error detected parsing the header

Akhila Mangipudi created COMPRESS-511:
-----------------------------------------

             Summary: Decompress tar failed. java.io.IOException: Error detected parsing the header
                 Key: COMPRESS-511
                 URL: https://issues.apache.org/jira/browse/COMPRESS-511
             Project: Commons Compress
          Issue Type: Bug
          Components: Archivers
    Affects Versions: 1.20
            Reporter: Akhila Mangipudi
         Attachments: layer1.tar

public static void main(String args[]) throws Exception {

//Send the TAR file as an argument
 String tarFileName = args[0];


 /* Read TAR File into TarArchiveInputStream */
 TarArchiveInputStream myTarFile=new TarArchiveInputStream(new FileInputStream(new File(tarFileName)));
 /* To read individual TAR file */
 TarArchiveEntry entry = null;
 String individualFiles;
 int offset;
 FileOutputStream outputFile=null;
 /* Create a loop to read every single entry in TAR file */
 while ((entry = myTarFile.getNextTarEntry()) != null) {
 /* Get the name of the file */
 individualFiles = entry.getName();
 /* Get Size of the file and create a byte array for the size */
 byte[] content = new byte[(int) entry.getSize()];
 offset=0;
 /* Some SOP statements to check progress */
 System.out.println("File Name in TAR File is: " + individualFiles);
 System.out.println("Size of the File is: " + entry.getSize());
 System.out.println("Byte Array length: " + content.length);
 /* Read file from the archive into byte array */
 myTarFile.read(content, offset, content.length - offset);
 /* Define OutputStream for writing the file */
 outputFile=new FileOutputStream(new File(individualFiles));

}

 

I was able to decompress the tar file in the Linux environment using the tar command. Following is the error when I run the code:

 

[ec2-user@ip-172-31-16-85 src]$ java TarToByteArray.java layer1.tar
Error: Could not find or load main class TarToByteArray.java
[ec2-user@ip-172-31-16-85 src]$ java TarToByteArray layer1.tar
Exception in thread "main" java.io.IOException: Error detected parsing the header
 at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:371)
 at TarToByteArray.main(TarToByteArray.java:19)
Caused by: java.lang.IllegalArgumentException: At offset 124, 12 byte binary number exceeds maximum signed long value
 at org.apache.commons.compress.archivers.tar.TarUtils.parseBinaryBigInteger(TarUtils.java:215)
 at org.apache.commons.compress.archivers.tar.TarUtils.parseOctalOrBinary(TarUtils.java:179)
 at org.apache.commons.compress.archivers.tar.TarArchiveEntry.parseTarHeader(TarArchiveEntry.java:1350)
 at org.apache.commons.compress.archivers.tar.TarArchiveEntry.<init>(TarArchiveEntry.java:438)
 at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:369)
 ... 1 more

 

 

Also attaching the tar file that I am using!



--
This message was sent by Atlassian Jira
(v8.3.4#803005)