I am trying to untar the tar file to a map
using Apache commons compress in Java. I am able to untar most of the tar files but few are failing with the below Exception. I am not sure what is causing the issue. is the tar file corrupted? I am able to untar the file using 7zip in windows but the same file failing when programatically untar it. I am using Appache commons-compress 1.18
java.io.IOException: Error detected parsing the header
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:285)
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextEntry(TarArchiveInputStream.java:552)
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:213)
at org.apache.commons.compress.archivers.tar.TarUtils.parseOctalOrBinary(TarUtils.java:177)
at org.apache.commons.compress.archivers.tar.TarArchiveEntry.parseTarHeader(TarArchiveEntry.java:1283)
at org.apache.commons.compress.archivers.tar.TarArchiveEntry.parseTarHeader(TarArchiveEntry.java:1266)
at org.apache.commons.compress.archivers.tar.TarArchiveEntry.<init>(TarArchiveEntry.java:404)
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:283)
... 25 more
below is my code
public static Map<String, byte[]> unTarToMap(byte[] b) throws IOException, ArchiveException {
final Map<String, byte[]> untaredFiles = new HashMap<>();
ByteArrayInputStream is = new ByteArrayInputStream(b);
final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
TarArchiveEntry entry;
while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
final ByteArrayOutputStream outputFileStream = new ByteArrayOutputStream();
IOUtils.copy(debInputStream, outputFileStream);
outputFileStream.close();
untaredFiles.put(entry.getName(), outputFileStream.toByteArray());
}
debInputStream.close();
return untaredFiles;
}