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;...@@ -15,6 +15,8 @@ const FEXTRA = 1 << 2;
15const FNAME = 1 << 3;15const FNAME = 1 << 3;
16const FCOMMENT = 1 << 4;16const FCOMMENT = 1 << 4;
1717
18const max_string_len = 1024;
19
18pub fn GzipStream(comptime ReaderType: type) type {20pub fn GzipStream(comptime ReaderType: type) type {
19 return struct {21 return struct {
20 const Self = @This();22 const Self = @This();
...@@ -71,7 +73,7 @@ pub fn GzipStream(comptime ReaderType: type) type {...@@ -71,7 +73,7 @@ pub fn GzipStream(comptime ReaderType: type) type {
71 filename = try source.readUntilDelimiterAlloc(73 filename = try source.readUntilDelimiterAlloc(
72 allocator,74 allocator,
73 0,75 0,
74 std.math.maxInt(usize),76 max_string_len,
75 );77 );
76 }78 }
77 errdefer if (filename) |p| allocator.free(p);79 errdefer if (filename) |p| allocator.free(p);
...@@ -81,7 +83,7 @@ pub fn GzipStream(comptime ReaderType: type) type {...@@ -81,7 +83,7 @@ pub fn GzipStream(comptime ReaderType: type) type {
81 comment = try source.readUntilDelimiterAlloc(83 comment = try source.readUntilDelimiterAlloc(
82 allocator,84 allocator,
83 0,85 0,
84 std.math.maxInt(usize),86 max_string_len,
85 );87 );
86 }88 }
87 errdefer if (comment) |p| allocator.free(p);89 errdefer if (comment) |p| allocator.free(p);