Skip to content

Commit 23fff34

Browse files
squeek502andrewrk
authored andcommitted
flate: Handle invalid block type
Fixes `panic: invalid enum value` when the type bits had the u2 value of 3. Contributes towards ziglang#24741
1 parent d984e7d commit 23fff34

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/std/compress/flate/Decompress.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const BlockType = enum(u2) {
3131
stored = 0,
3232
fixed = 1,
3333
dynamic = 2,
34+
invalid = 3,
3435
};
3536

3637
const State = union(enum) {
@@ -49,6 +50,7 @@ pub const Error = Container.Error || error{
4950
InvalidCode,
5051
InvalidMatch,
5152
WrongStoredBlockNlen,
53+
InvalidBlockType,
5254
InvalidDynamicBlockHeader,
5355
ReadFailed,
5456
OversubscribedHuffmanTree,
@@ -360,6 +362,7 @@ fn streamInner(d: *Decompress, w: *Writer, limit: std.Io.Limit) (Error || Reader
360362

361363
continue :sw .dynamic_block;
362364
},
365+
.invalid => return error.InvalidBlockType,
363366
}
364367
},
365368
.stored_block => |remaining_len| {
@@ -1141,6 +1144,10 @@ test "puff09" {
11411144
try testDecompress(.raw, @embedFile("testdata/fuzz/puff09.input"), "P");
11421145
}
11431146

1147+
test "invalid block type" {
1148+
try testFailure(.raw, &[_]u8{0b110}, error.InvalidBlockType);
1149+
}
1150+
11441151
test "bug 18966" {
11451152
try testDecompress(
11461153
.gzip,

0 commit comments

Comments
 (0)