Skip to content

Commit

Permalink
fix: infinite loop during 'out of codes'
Browse files Browse the repository at this point in the history
Fixes #2
  • Loading branch information
ianic committed Feb 8, 2024
1 parent 40a5b75 commit 5b2f446
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/inflate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ pub fn Inflate(comptime container: Container, comptime ReaderType: type) type {
// return symbol.
inline fn decodeSymbol(self: *Self, decoder: anytype) !hfd.Symbol {
const sym = decoder.find(try self.bits.peekF(u15, F.buffered | F.reverse));
if (sym.code_bits == 0) return error.CorruptInput;
self.bits.shift(sym.code_bits);
return sym;
}
Expand Down Expand Up @@ -482,3 +483,12 @@ test "lengths overflow" {

try testing.expectError(error.CorruptInput, decompress(.raw, fb.reader(), al.writer()));
}

test "fix: infinite loop during 'out of codes'" {
const data = "\x950\x00\x0000000";

var fb = std.io.fixedBufferStream(data);
var al = std.ArrayList(u8).init(testing.allocator);
defer al.deinit();
try testing.expectError(error.CorruptInput, decompress(.raw, fb.reader(), al.writer()));
}

0 comments on commit 5b2f446

Please sign in to comment.