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 {...@@ -33,9 +33,11 @@ pub fn GzipStream(comptime ReaderType: type) type {
33 read_amt: usize,33 read_amt: usize,
3434
35 info: struct {35 info: struct {
36 extra: ?[]const u8,
36 filename: ?[]const u8,37 filename: ?[]const u8,
37 comment: ?[]const u8,38 comment: ?[]const u8,
38 modification_time: u32,39 modification_time: u32,
40 operating_system: u8,
39 },41 },
4042
41 fn init(allocator: mem.Allocator, source: ReaderType) !Self {43 fn init(allocator: mem.Allocator, source: ReaderType) !Self {
...@@ -59,33 +61,27 @@ pub fn GzipStream(comptime ReaderType: type) type {...@@ -59,33 +61,27 @@ pub fn GzipStream(comptime ReaderType: type) type {
59 // Operating system where the compression took place61 // Operating system where the compression took place
60 const OS = header[9];62 const OS = header[9];
61 _ = XFL;63 _ = XFL;
62 _ = OS;
6364
64 if (FLG & FEXTRA != 0) {65 const extra = if (FLG & FEXTRA != 0) blk: {
65 // Skip the extra data, we could read and expose it to the user
66 // if somebody needs it.
67 const len = try source.readIntLittle(u16);66 const len = try source.readIntLittle(u16);
68 try source.skipBytes(len, .{});67 const tmp_buf = try allocator.alloc(u8, len);
69 }68 errdefer allocator.free(tmp_buf);
7069
71 var filename: ?[]const u8 = null;70 try source.readNoEof(tmp_buf);
72 if (FLG & FNAME != 0) {71 break :blk tmp_buf;
73 filename = try source.readUntilDelimiterAlloc(72 } else null;
74 allocator,73 errdefer if (extra) |p| allocator.free(p);
75 0,74
76 max_string_len,75 const filename = if (FLG & FNAME != 0)
77 );76 try source.readUntilDelimiterAlloc(allocator, 0, max_string_len)
78 }77 else
78 null;
79 errdefer if (filename) |p| allocator.free(p);79 errdefer if (filename) |p| allocator.free(p);
8080
81 var comment: ?[]const u8 = null;81 const comment = if (FLG & FCOMMENT != 0)
82 if (FLG & FCOMMENT != 0) {82 try source.readUntilDelimiterAlloc(allocator, 0, max_string_len)
83 comment = try source.readUntilDelimiterAlloc(83 else
84 allocator,84 null;
85 0,
86 max_string_len,
87 );
88 }
89 errdefer if (comment) |p| allocator.free(p);85 errdefer if (comment) |p| allocator.free(p);
9086
91 if (FLG & FHCRC != 0) {87 if (FLG & FHCRC != 0) {
...@@ -102,7 +98,9 @@ pub fn GzipStream(comptime ReaderType: type) type {...@@ -102,7 +98,9 @@ pub fn GzipStream(comptime ReaderType: type) type {
102 .info = .{98 .info = .{
103 .filename = filename,99 .filename = filename,
104 .comment = comment,100 .comment = comment,
101 .extra = extra,
105 .modification_time = MTIME,102 .modification_time = MTIME,
103 .operating_system = OS,
106 },104 },
107 .read_amt = 0,105 .read_amt = 0,
108 };106 };
...@@ -110,6 +108,8 @@ pub fn GzipStream(comptime ReaderType: type) type {...@@ -110,6 +108,8 @@ pub fn GzipStream(comptime ReaderType: type) type {
110108
111 pub fn deinit(self: *Self) void {109 pub fn deinit(self: *Self) void {
112 self.inflater.deinit();110 self.inflater.deinit();
111 if (self.info.extra) |extra|
112 self.allocator.free(extra);
113 if (self.info.filename) |filename|113 if (self.info.filename) |filename|
114 self.allocator.free(filename);114 self.allocator.free(filename);
115 if (self.info.comment) |comment|115 if (self.info.comment) |comment|