ianic/flate

Infinite loop during another test case from the puff.c Makefile

squeek502 opened this issue · 1 comments

Reproduction:

const std = @import("std");
const flate = @import("flate");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer std.debug.assert(gpa.deinit() == .ok);
    const allocator = gpa.allocator();

    const data = "\x04\x00\xfe\xff";

    var fbs = std.io.fixedBufferStream(data);
    const reader = fbs.reader();
    var inflate = flate.raw.decompressor(reader);

    const inflated = inflate.reader().readAllAlloc(allocator, std.math.maxInt(usize)) catch {
        return;
    };
    defer allocator.free(inflated);
}

This test comes from a puff.c (deflate reference implementation) test case within its Makefile: https://github.com/madler/zlib/blob/504403f3e468bca2dc85c055d96ad392e9c7aae0/contrib/puff/Makefile#L34. It's used as part of the input corpus for fuzz testing the deflate implementation here: https://github.com/squeek502/zig-std-lib-fuzzing/blob/master/inputs/deflate/puff13

Thanks for pointing to this corpus of fuzzing tests.

I copied them here. Hope that is OK?
And make them all pass without panicking.