Skip to content

Commit ae99c94

Browse files
committed
[LZMA] Fix incorrect check for empty out window
This was caused by incorrectly assuming that out window (dictionary) always starts at 0 index. This is not correct in the case of LZMA2 where dictionary may have been reset, but the out window is technically not an empty array.
1 parent 43132fc commit ae99c94

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sources/LZMA/LZMADecoder.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ struct LZMADecoder {
125125

126126
// DECODE LITERAL:
127127
/// Previous literal (zero, if there was none).
128-
let prevByte = dictEnd == 0 ? 0 : self.byte(at: 1).toInt()
128+
let prevByte = dictEnd == dictStart ? 0 : self.byte(at: 1).toInt()
129129
/// Decoded symbol. Initial value is 1.
130130
var symbol = 1
131131
/**
@@ -179,7 +179,7 @@ struct LZMADecoder {
179179
if uncompressedSize == 0 {
180180
throw LZMAError.exceededUncompressedSize
181181
}
182-
if dictEnd == 0 {
182+
if dictEnd == dictStart {
183183
throw LZMAError.windowIsEmpty
184184
}
185185
if rangeDecoder.decode(bitWithProb: &probabilities[205 + state]) == 0 {

0 commit comments

Comments
 (0)