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] [Updated] (COMPRESS-270) TarArchiveInputStream fails to read PAX header from InputStream
Date Thu, 27 Mar 2014 11:26:14 GMT

     [ https://issues.apache.org/jira/browse/COMPRESS-270?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Patrik Burkhalter updated COMPRESS-270:
---------------------------------------

    Description: 
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];
int got = 0;
while((ch = i.read()) != -1) {
	rest[got] = (byte) ch;
	got++;
	if(got == len - read) {
		break;
	}
}
if (got != len - read){
	throw new IOException("Failed to read "
		+ "Paxheader. Expected "
		+ (len - read)
		+ " bytes, read "
		+ got);
}
{code}

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

  was:
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];
int got = 0;
while((ch = i.read()) != -1) {
	rest[got] = (byte) ch;
	got++;
	if(got == len - read) {
		break;
	}
}
{code}

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


> 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
>              Labels: tar
>
> 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];
> int got = 0;
> while((ch = i.read()) != -1) {
> 	rest[got] = (byte) ch;
> 	got++;
> 	if(got == len - read) {
> 		break;
> 	}
> }
> if (got != len - read){
> 	throw new IOException("Failed to read "
> 		+ "Paxheader. Expected "
> 		+ (len - read)
> 		+ " bytes, read "
> 		+ got);
> }
> {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