| author | |
| committer | |
| log | 30f15e3afe38afb6b8c1a378c326d29d2ebab378 |
| tree | 04c2203cdeecdca028093b4d1d58853210d914fc |
| parent | 8802ec583b376101ee7fcb0a64cf937b90dc6130 |
Running fuzzing tar test with [zig std lib
fuzzing](https://github.com/squeek502/zig-std-lib-fuzzing) reached and
assert in tar implementation. Assert (in std lib) should not be
reachable by external input, so I'm fixing this to return error.3 files changed, 5 insertions(+), 1 deletions(-)
lib/std/tar.zig+1-1| ... | @@ -300,7 +300,7 @@ fn Iterator(comptime ReaderType: type) type { | ... | @@ -300,7 +300,7 @@ fn Iterator(comptime ReaderType: type) type { |
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | inline fn readString(self: *Self, size: usize, buffer: []u8) ![]const u8 { | 302 | inline fn readString(self: *Self, size: usize, buffer: []u8) ![]const u8 { |
| 303 | assert(buffer.len >= size); | 303 | if (size > buffer.len) return error.TarCorruptInput; |
| 304 | const buf = buffer[0..size]; | 304 | const buf = buffer[0..size]; |
| 305 | try self.reader.readNoEof(buf); | 305 | try self.reader.readNoEof(buf); |
| 306 | return nullStr(buf); | 306 | return nullStr(buf); |
lib/std/tar/test.zig+4| ... | @@ -313,6 +313,10 @@ test "tar run Go test cases" { | ... | @@ -313,6 +313,10 @@ test "tar run Go test cases" { |
| 313 | }, | 313 | }, |
| 314 | }, | 314 | }, |
| 315 | }, | 315 | }, |
| 316 | .{ | ||
| 317 | .data = @embedFile("testdata/fuzz1.tar"), | ||
| 318 | .err = error.TarCorruptInput, | ||
| 319 | }, | ||
| 316 | }; | 320 | }; |
| 317 | 321 | ||
| 318 | for (cases) |case| { | 322 | for (cases) |case| { |
lib/std/tar/testdata/fuzz1.tar created| Binary files /dev/null and b/lib/std/tar/testdata/fuzz1.tar differ | |||