authorgravatar for emilliken@gmail.commllken <emilliken@gmail.com> 2022-10-12 19:46:03+07:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-18 15:12:46+02:00
log5db1a3cd33339bb28e1354b58374bf1c18e15e6e
tree388b9d2d16d373a0881820cb2e815a3c36e967f9
parent684264908e50bc8537fc10859e93ccdf8d94509e

gzip: add bounds for safer header parsing


1 files changed, 4 insertions(+), 2 deletions(-)

lib/std/compress/gzip.zig+4-2
......@@ -15,6 +15,8 @@ const FEXTRA = 1 << 2;
1515const FNAME = 1 << 3;
1616const FCOMMENT = 1 << 4;
1717
18const max_string_len = 1024;
19
1820pub fn GzipStream(comptime ReaderType: type) type {
1921 return struct {
2022 const Self = @This();
......@@ -71,7 +73,7 @@ pub fn GzipStream(comptime ReaderType: type) type {
7173 filename = try source.readUntilDelimiterAlloc(
7274 allocator,
7375 0,
74 std.math.maxInt(usize),
76 max_string_len,
7577 );
7678 }
7779 errdefer if (filename) |p| allocator.free(p);
......@@ -81,7 +83,7 @@ pub fn GzipStream(comptime ReaderType: type) type {
8183 comment = try source.readUntilDelimiterAlloc(
8284 allocator,
8385 0,
84 std.math.maxInt(usize),
86 max_string_len,
8587 );
8688 }
8789 errdefer if (comment) |p| allocator.free(p);