diff options
| author | dweiller <4678790+dweiller@users.noreplay.github.com> | 2023-01-26 17:12:40 +1100 |
|---|---|---|
| committer | dweiller <4678790+dweiller@users.noreplay.github.com> | 2023-02-20 09:09:06 +1100 |
| commit | 1e5b8be5099d976628aaa3fc4208a0bbd45c7700 (patch) | |
| tree | bc7d31255487d1e4acb0033eb00257fdd44d9f6f /lib/std | |
| parent | e2306ef0a027ab6257613dad234551a013729de3 (diff) | |
| download | zig-1e5b8be5099d976628aaa3fc4208a0bbd45c7700.tar.gz zig-1e5b8be5099d976628aaa3fc4208a0bbd45c7700.zip | |
std.compress.zstandard: add window size limit param
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/compress/zstandard/decompress.zig | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/std/compress/zstandard/decompress.zig b/lib/std/compress/zstandard/decompress.zig index c82e4f71a3..6a1ab364e7 100644 --- a/lib/std/compress/zstandard/decompress.zig +++ b/lib/std/compress/zstandard/decompress.zig @@ -562,7 +562,12 @@ pub fn decodeZStandardFrame(dest: []u8, src: []const u8, verify_checksum: bool) /// `decodeZStandardFrame()`. Returns `error.WindowSizeUnknown` if the frame /// does not declare its content size or a window descriptor (this indicates a /// malformed frame). -pub fn decodeZStandardFrameAlloc(allocator: std.mem.Allocator, src: []const u8, verify_checksum: bool) ![]u8 { +pub fn decodeZStandardFrameAlloc( + allocator: std.mem.Allocator, + src: []const u8, + verify_checksum: bool, + window_size_max: usize, +) ![]u8 { var result = std.ArrayList(u8).init(allocator); assert(readInt(u32, src[0..4]) == frame.ZStandard.magic_number); var consumed_count: usize = 4; @@ -572,7 +577,10 @@ pub fn decodeZStandardFrameAlloc(allocator: std.mem.Allocator, src: []const u8, if (frame_header.descriptor.dictionary_id_flag != 0) return error.DictionaryIdFlagUnsupported; const window_size_raw = frameWindowSize(frame_header) orelse return error.WindowSizeUnknown; - const window_size = std.math.cast(usize, window_size_raw) orelse return error.WindowTooLarge; + const window_size = if (window_size_raw > window_size_max) + return error.WindowTooLarge + else + @intCast(usize, window_size_raw); const should_compute_checksum = frame_header.descriptor.content_checksum_flag and verify_checksum; var hash = if (should_compute_checksum) std.hash.XxHash64.init(0) else null; |
