diff --git a/WHATSNEW b/WHATSNEW index c8fbe501d..f4c64ef80 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -11,6 +11,9 @@ Fixed bugs: fields. Bugzilla Report 56641 +* TarArchiveInputStream could throw IOException when reading PAX + headers from a "slow" InputStream. + Other changes: -------------- diff --git a/src/main/org/apache/tools/tar/TarInputStream.java b/src/main/org/apache/tools/tar/TarInputStream.java index 62bbd625f..154f14e2e 100644 --- a/src/main/org/apache/tools/tar/TarInputStream.java +++ b/src/main/org/apache/tools/tar/TarInputStream.java @@ -431,18 +431,22 @@ public class TarInputStream extends FilterInputStream { if (ch == '='){ // end of keyword String keyword = coll.toString("UTF-8"); // Get rest of entry - byte[] rest = new byte[len - read]; - int got = i.read(rest); - if (got != len - read){ + final int restLen = len - read; + byte[] rest = new byte[restLen]; + int got = 0; + while (got < restLen && (ch = i.read()) != -1) { + rest[got++] = (byte) ch; + } + if (got != restLen) { throw new IOException("Failed to read " + "Paxheader. Expected " - + (len - read) + + restLen + " bytes, read " + got); } // Drop trailing NL String value = new String(rest, 0, - len - read - 1, "UTF-8"); + restLen - 1, "UTF-8"); headers.put(keyword, value); break; }