zig
zig copied to clipboard
Reading into empty buffer will panic std.compress.flate.decompressor.
Zig Version
0.13.0-dev.75+5c9eb4081
Steps to Reproduce and Observed Behavior
This code will produce panic:
const std = @import("std");
pub fn main() !void {
const bytes = &[_]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 fbs = std.io.fixedBufferStream(bytes);
var gz = std.compress.flate.decompressor(fbs.reader());
var tmp: [0]u8 = undefined;
_ = try gz.read(&tmp);
}
Panic:
thread 22216 panic: index out of bounds: index 12, len 0
zig\lib\std\compress\flate\inflate.zig:352:27: 0xdf1287 in read (check.exe.obj)
@memcpy(buffer[0..out.len], out);
^
main.zig:11:20: 0xdf109f in main (check.exe.obj)
_ = try gz.read(&tmp);
Expected Behavior
Not panic.