[
https://issues.apache.org/jira/browse/COMPRESS-270?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13950378#comment-13950378
]
Stefan Bodewig commented on COMPRESS-270:
-----------------------------------------
there is IOUtils#readFully and I had hoped I had caught all places where we
expected read to succeed by now. Obviously not. Sorry.
This case is fixed with svn revision 1582594 but I'll leave this issue open as
a reminder to scan through the code base once again.
> 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
> Fix For: 1.9
>
>
> 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)