diff --git a/WHATSNEW b/WHATSNEW index ccf3548aa..b74181ceb 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -38,6 +38,9 @@ Fixed bugs: getting executed twice. Bugzilla Report 58886 + * TarInputStream now properly extraxt directory entries with a + non-zero size. + Other changes: -------------- diff --git a/src/main/org/apache/tools/tar/TarInputStream.java b/src/main/org/apache/tools/tar/TarInputStream.java index 57827a2cd..964e5c5f5 100644 --- a/src/main/org/apache/tools/tar/TarInputStream.java +++ b/src/main/org/apache/tools/tar/TarInputStream.java @@ -177,6 +177,9 @@ public class TarInputStream extends FilterInputStream { */ @Override public int available() throws IOException { + if (isDirectory()) { + return 0; + } if (entrySize - entryOffset > Integer.MAX_VALUE) { return Integer.MAX_VALUE; } @@ -195,6 +198,9 @@ public class TarInputStream extends FilterInputStream { */ @Override public long skip(long numToSkip) throws IOException { + if (numToSkip <= 0 || isDirectory()) { + return 0; + } // REVIEW // This is horribly inefficient, but it ensures that we // properly skip over bytes via the TarBuffer... @@ -563,7 +569,7 @@ public class TarInputStream extends FilterInputStream { public int read(byte[] buf, int offset, int numToRead) throws IOException { int totalRead = 0; - if (entryOffset >= entrySize) { + if (entryOffset >= entrySize || isDirectory()) { return -1; } @@ -656,5 +662,9 @@ public class TarInputStream extends FilterInputStream { public boolean canReadEntryData(TarEntry te) { return !te.isGNUSparse(); } + + private boolean isDirectory() { + return currEntry != null && currEntry.isDirectory(); + } }