commit 23fff3442de38877c556f3cda19f3cccef255f7a (tree)
parent d984e7d2fa4a88a86deff36f33c70b2f4ced7d02
Author: Ryan Liptak <squeek502@hotmail.com>
Date: Fri, 8 Aug 2025 01:37:59 -0700
flate: Handle invalid block type
Fixes `panic: invalid enum value` when the type bits had the u2 value of 3.
Contributes towards #24741
Diffstat:
1 file changed, 7 insertions(+), 0 deletions(-)
diff --git a/lib/std/compress/flate/Decompress.zig b/lib/std/compress/flate/Decompress.zig
@@ -31,6 +31,7 @@ const BlockType = enum(u2) {
stored = 0,
fixed = 1,
dynamic = 2,
+ invalid = 3,
};
const State = union(enum) {
@@ -49,6 +50,7 @@ pub const Error = Container.Error || error{
InvalidCode,
InvalidMatch,
WrongStoredBlockNlen,
+ InvalidBlockType,
InvalidDynamicBlockHeader,
ReadFailed,
OversubscribedHuffmanTree,
@@ -360,6 +362,7 @@ fn streamInner(d: *Decompress, w: *Writer, limit: std.Io.Limit) (Error || Reader
continue :sw .dynamic_block;
},
+ .invalid => return error.InvalidBlockType,
}
},
.stored_block => |remaining_len| {
@@ -1141,6 +1144,10 @@ test "puff09" {
try testDecompress(.raw, @embedFile("testdata/fuzz/puff09.input"), "P");
}
+test "invalid block type" {
+ try testFailure(.raw, &[_]u8{0b110}, error.InvalidBlockType);
+}
+
test "bug 18966" {
try testDecompress(
.gzip,