aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2017-10-11 18:59:36 +0300
committerLasse Collin <lasse.collin@tukaani.org>2017-10-11 18:59:36 +0300
commit59b1d5cdf69c7c363dc88b4d4f911c5d886064fc (patch)
tree0d2b9d53dd80d9311cb5c793c78f9e27fdfe64de
parentb9e2559c0cf7744f220150965ba12eb3847a5de7 (diff)
downloadxz-java-59b1d5cdf69c7c363dc88b4d4f911c5d886064fc.tar.gz
Fix LZMA2InputStream.available() for uncompressed chunks.
It could return a too high value when in the middle of an uncompressed chunk.
-rw-r--r--src/org/tukaani/xz/LZMA2InputStream.java9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/org/tukaani/xz/LZMA2InputStream.java b/src/org/tukaani/xz/LZMA2InputStream.java
index d176507..bcc4919 100644
--- a/src/org/tukaani/xz/LZMA2InputStream.java
+++ b/src/org/tukaani/xz/LZMA2InputStream.java
@@ -51,7 +51,7 @@ public class LZMA2InputStream extends InputStream {
private LZMADecoder lzma;
private int uncompressedSize = 0;
- private boolean isLZMAChunk;
+ private boolean isLZMAChunk = false;
private boolean needDictReset = true;
private boolean needProps = true;
@@ -323,7 +323,9 @@ public class LZMA2InputStream extends InputStream {
* In LZMA2InputStream, the return value will be non-zero when the
* decompressor is in the middle of an LZMA2 chunk. The return value
* will then be the number of uncompressed bytes remaining from that
- * chunk.
+ * chunk. The return value can also be non-zero in the middle of
+ * an uncompressed chunk, but then the return value depends also on
+ * the <code>available()</code> method of the underlying InputStream.
*
* @return the number of uncompressed bytes that can be read
* without blocking
@@ -335,7 +337,8 @@ public class LZMA2InputStream extends InputStream {
if (exception != null)
throw exception;
- return uncompressedSize;
+ return isLZMAChunk ? uncompressedSize
+ : Math.min(uncompressedSize, in.available());
}
/**