Skip to content

Commit 12c75fd

Browse files
committed
Fix ArrayCache usage with LZMAInputStream
Add a missing initialization to LZDecoder's constructor. The same initialization is done in LZDecoder.reset(). LZMA2InputStream always calls it before decoding anything, thus this bug didn't break LZMA2 decoding. However, LZMAInputStream has no reason to call LZDecoder.reset(), and thus the missing initialization in the constructor meant that ArrayCache didn't work with LZMAInputStream. Fixes: c5569e4 ("Add ArrayCache support to LZMA and LZMA2 coders, part 1.") Fixes: #23
1 parent e52d9ad commit 12c75fd

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/org/tukaani/xz/lz/LZDecoder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public LZDecoder(int dictSize, byte[] presetDict, ArrayCache arrayCache) {
2424
bufSize = dictSize;
2525
buf = arrayCache.getByteArray(bufSize, false);
2626

27+
// getByte(0) needs to return 0x00 when no data has been decompressed.
28+
// This requires initializing only one byte, so don't pass "true" as
29+
// the second argument in the above arrayCache.getByteArray call.
30+
//
31+
// Note that LZMA2InputStream calls LZDecoder.reset() before decoding
32+
// anything, thus it doesn't break even if this initialization was
33+
// missing here. But LZMAInputStream has no reason to call reset().
34+
buf[bufSize - 1] = 0x00;
35+
2736
if (presetDict != null) {
2837
pos = Math.min(presetDict.length, dictSize);
2938
full = pos;

0 commit comments

Comments
 (0)