authorgravatar for emilliken@gmail.commllken <emilliken@gmail.com> 2022-10-14 13:07:25+07:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-18 15:13:22+02:00
logb25fc18aa657fbc5b0fbc332123fdd0121d8ca1c
treeaa8758edf54a3bd6af21f20998dd013ad8fafd98
parent5db1a3cd33339bb28e1354b58374bf1c18e15e6e

gzip: add missing fields to header parsing


1 files changed, 23 insertions(+), 23 deletions(-)

lib/std/compress/gzip.zig+23-23
......@@ -33,9 +33,11 @@ pub fn GzipStream(comptime ReaderType: type) type {
3333 read_amt: usize,
3434
3535 info: struct {
36 extra: ?[]const u8,
3637 filename: ?[]const u8,
3738 comment: ?[]const u8,
3839 modification_time: u32,
40 operating_system: u8,
3941 },
4042
4143 fn init(allocator: mem.Allocator, source: ReaderType) !Self {
......@@ -59,33 +61,27 @@ pub fn GzipStream(comptime ReaderType: type) type {
5961 // Operating system where the compression took place
6062 const OS = header[9];
6163 _ = XFL;
62 _ = OS;
6364
64 if (FLG & FEXTRA != 0) {
65 // Skip the extra data, we could read and expose it to the user
66 // if somebody needs it.
65 const extra = if (FLG & FEXTRA != 0) blk: {
6766 const len = try source.readIntLittle(u16);
68 try source.skipBytes(len, .{});
69 }
70
71 var filename: ?[]const u8 = null;
72 if (FLG & FNAME != 0) {
73 filename = try source.readUntilDelimiterAlloc(
74 allocator,
75 0,
76 max_string_len,
77 );
78 }
67 const tmp_buf = try allocator.alloc(u8, len);
68 errdefer allocator.free(tmp_buf);
69
70 try source.readNoEof(tmp_buf);
71 break :blk tmp_buf;
72 } else null;
73 errdefer if (extra) |p| allocator.free(p);
74
75 const filename = if (FLG & FNAME != 0)
76 try source.readUntilDelimiterAlloc(allocator, 0, max_string_len)
77 else
78 null;
7979 errdefer if (filename) |p| allocator.free(p);
8080
81 var comment: ?[]const u8 = null;
82 if (FLG & FCOMMENT != 0) {
83 comment = try source.readUntilDelimiterAlloc(
84 allocator,
85 0,
86 max_string_len,
87 );
88 }
81 const comment = if (FLG & FCOMMENT != 0)
82 try source.readUntilDelimiterAlloc(allocator, 0, max_string_len)
83 else
84 null;
8985 errdefer if (comment) |p| allocator.free(p);
9086
9187 if (FLG & FHCRC != 0) {
......@@ -102,7 +98,9 @@ pub fn GzipStream(comptime ReaderType: type) type {
10298 .info = .{
10399 .filename = filename,
104100 .comment = comment,
101 .extra = extra,
105102 .modification_time = MTIME,
103 .operating_system = OS,
106104 },
107105 .read_amt = 0,
108106 };
......@@ -110,6 +108,8 @@ pub fn GzipStream(comptime ReaderType: type) type {
110108
111109 pub fn deinit(self: *Self) void {
112110 self.inflater.deinit();
111 if (self.info.extra) |extra|
112 self.allocator.free(extra);
113113 if (self.info.filename) |filename|
114114 self.allocator.free(filename);
115115 if (self.info.comment) |comment|