commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrik Burkhalter (JIRA)" <j...@apache.org>
Subject [jira] [Created] (COMPRESS-270) TarArchiveInputStream fails to read PAX header from InputStream
Date Thu, 27 Mar 2014 09:51:14 GMT
Patrik Burkhalter created COMPRESS-270:
------------------------------------------

             Summary: TarArchiveInputStream fails to read PAX header from InputStream
                 Key: COMPRESS-270
                 URL: https://issues.apache.org/jira/browse/COMPRESS-270
             Project: Commons Compress
          Issue Type: Bug
          Components: Archivers
    Affects Versions: 1.8
            Reporter: Patrik Burkhalter


We have a scenario with a "slow" {{InputStream}} and are facing {{IOExceptions}} with {{TarArchiveEntry#getNextTarEntry()}}.

If the {{InputStream}} does not deliver fast enough, {{TarArchiveEntry#parsePaxHeaders(InputStream
i)}} fails at this location:

{code:title=TarArchiveInputStream.java|borderStyle=solid}
// Get rest of entry
byte[] rest = new byte[len - read];
int got = i.read(rest);
if (got != len - read){
	throw new IOException("Failed to read "
		+ "Paxheader. Expected "
		+ (len - read)
		+ " bytes, read "
		+ got);
}
{code}

We would suggest to change the code to something like this:

{code:title=TarArchiveInputStream.java|borderStyle=solid}
 // Get rest of entry
byte[] rest = new byte[len - read];
byte[] buffer = new byte[len - read];
int got = 0;
int destPos = 0;
while((got = i.read(buffer)) != -1) {
	System.arraycopy(buffer, 0, rest, destPos, got);
	destPos += got;
}
if (destPos != len - read){
	throw new IOException("Failed to read "
		+ "Paxheader. Expected "
		+ (len - read)
		+ " bytes, read "
		+ destPos);
}
{code}

This would make sure, that it gets all bytes of the PAX header value.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message