zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit fa4a626faccd1c80d3509ed8d95152fc100a5925 (tree)
parent 33c3bf06317a19ec7cb2f7fdbea51acae66ef963
Author: Pavel Verigo <58272683+pavelverigo@users.noreply.github.com>
Date:   Wed,  8 May 2024 16:29:29 +0200

std.compress.flate: fix panic when reading into empty buffer

Diffstat:
Mlib/std/compress/flate/inflate.zig | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/lib/std/compress/flate/inflate.zig b/lib/std/compress/flate/inflate.zig @@ -347,6 +347,7 @@ pub fn Inflate(comptime container: Container, comptime LookaheadType: type, comp /// If the number of bytes read is 0, it means end of stream. /// End of stream is not an error condition. pub fn read(self: *Self, buffer: []u8) Error!usize { + if (buffer.len == 0) return 0; const out = try self.get(buffer.len); @memcpy(buffer[0..out.len], out); return out.len; @@ -556,3 +557,14 @@ test "bug 18966" { try decompress(.gzip, in.reader(), out.writer()); try testing.expectEqualStrings(expect, out.items); } + +test "bug 19895" { + const input = &[_]u8{ + 0b0000_0001, 0b0000_1100, 0x00, 0b1111_0011, 0xff, // deflate fixed buffer header len, nlen + 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', 0x0a, // non compressed data + }; + var in = std.io.fixedBufferStream(input); + var decomp = decompressor(.raw, in.reader()); + var buf: [0]u8 = undefined; + try testing.expectEqual(0, try decomp.read(&buf)); +}