You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Dye357 (JIRA)" <ji...@apache.org> on 2016/02/04 14:13:39 UTC
[jira] [Commented] (COMPRESS-330) Tar UnArchive Fails when archive
contains directory sizes which are non-zero.
[ https://issues.apache.org/jira/browse/COMPRESS-330?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15132280#comment-15132280 ]
Dye357 commented on COMPRESS-330:
---------------------------------
I can confirm the tar archive was created by 7zip, still trying to figure out which version. (The file was sent to me by another party)
I debugged the tar in question this morning, I discovered the entrySize for the directory which causes the error is coming back as 32768. I thought that was a little suspicious since that is the max negative size of an int in various languages. So I quick wrote a unit test just to understand how the parseOctalOrBinary Method worked:
@Test
public void testParseOctal() {
byte[] buffer = new byte[12];
buffer[0] = 32;
buffer[1] = 32;
buffer[2] = 32;
buffer[3] = 32;
buffer[4] = 32;
buffer[5] = 49;
buffer[6] = 48;
buffer[7] = 48;
buffer[8] = 48;
buffer[9] = 48;
buffer[10] = 48;
buffer[11] = 32;
long result = TarUtils.parseOctalOrBinary(buffer, 0, 12);
assert result == 32768;
}
The byte array above is an exact copy of the entry size header of the file in question - I tried setting the entry size in my dummy tar to that exact byte array but my unit test still passes. When I use the file in question I get an IllegalArugmentEcxeption: Invalid byte 85 at offset 0 in '<randomBinaryString>' len=12
> Tar UnArchive Fails when archive contains directory sizes which are non-zero.
> -----------------------------------------------------------------------------
>
> Key: COMPRESS-330
> URL: https://issues.apache.org/jira/browse/COMPRESS-330
> Project: Commons Compress
> Issue Type: Bug
> Components: Archivers
> Affects Versions: 1.10
> Environment: Java 1.8
> Reporter: Dye357
> Priority: Minor
> Attachments: Compress-330.patch
>
>
> Tar UnArchive Fails when archive contains directory sizes which are non-zero. I recently came across a set of files which failed to extract with commons-compress but I was able to successfully extract the files with GNU tar.
> The problem is TarArchiveInputStream.java gets the size of each entry in a tar archive to determine how many bytes to read ahead. Directories are always sized 0 bytes, however its technically possible a tar archive contains a size for a directory. This causes the Input Stream to loose it's place and eventually results in an exception being thrown.
> I was able to implement a proof-of-concept fix by checking if an entity is a directory and setting the directory size to 0. (A directory with Files in a Tar Archive still has a size of 0 as the directory itself does not have size in the archive.)
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)