Skip to content

std.compress.xz: Integer overflows found via fuzzing #14500

@squeek502

Description

@squeek502

Zig Version

0.11.0-dev.1502+d6b430b52

Steps to Reproduce and Observed Behavior

Meant to do some fuzz testing while this was still a PR (#14434) but didn't get around to it. So far I've only fuzz tested to find crashes, not verify correctness, and I've only found 3 unique integer overflow locations.

The minimized test cases as files can be found here (note: there are some test cases that trigger the same/similar crashes):

xz-fuzzed-crashes-20230202.zip

(if it makes it easier, it's possible to use zigescape to get Zig string literals from each file's contents)

The integer overflows can be reproduced by running the above inputs through the decompress function here:

fn decompress(data: []const u8) ![]u8 {
var in_stream = std.io.fixedBufferStream(data);
var xz_stream = try xz.decompress(testing.allocator, in_stream.reader());
defer xz_stream.deinit();
return xz_stream.reader().readAllAlloc(testing.allocator, std.math.maxInt(usize));
}

Fuzzer code can be found here:

https://github.com/squeek502/zig-std-lib-fuzzing/blob/master/fuzzers/xz.zig

cc @FnControlOption

Expected Behavior

The xz decompressor to avoid integer overflow on all inputs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstandard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions