Skip to content

Commit 36f1f4f

Browse files
committed
deflate: Update fuzzed test cases and add InvalidTree test cases
1 parent 933fd51 commit 36f1f4f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/std/compress/deflate.zig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,22 @@ test "empty distance alphabet" {
702702

703703
test "inflateStream fuzzing" {
704704
// see https://github.com/ziglang/zig/issues/9842
705-
try std.testing.expectError(error.EndOfStream, testInflate("\x950000"));
705+
try std.testing.expectError(error.EndOfStream, testInflate("\x95\x90=o\xc20\x10\x86\xf30"));
706706
try std.testing.expectError(error.OutOfCodes, testInflate("\x950\x00\x0000000"));
707+
708+
// Huffman.construct errors
709+
// lencode
710+
try std.testing.expectError(error.InvalidTree, testInflate("\x950000"));
711+
try std.testing.expectError(error.InvalidTree, testInflate("\x05000"));
712+
// hlen
713+
try std.testing.expectError(error.InvalidTree, testInflate("\x05\xea\x01\t\x00\x00\x00\x01\x00\\\xbf.\t\x00"));
714+
// hdist
715+
try std.testing.expectError(error.InvalidTree, testInflate("\x05\xe0\x01A\x00\x00\x00\x00\x10\\\xbf."));
716+
717+
// Huffman.construct -> error.IncompleteSet returns that shouldn't give error.InvalidTree
718+
// (like the "empty distance alphabet" test but for ndist instead of nlen)
719+
try std.testing.expectError(error.EndOfStream, testInflate("\x05\xe0\x01\t\x00\x00\x00\x00\x10\\\xbf\xce"));
720+
try testInflate("\x15\xe0\x01\t\x00\x00\x00\x00\x10\\\xbf.0");
707721
}
708722

709723
fn testInflate(data: []const u8) !void {

0 commit comments

Comments
 (0)