Skip to content

Working with flate.Decompress is maybe buggy #24695

@mrjbq7

Description

@mrjbq7

Zig Version

0.15.0-dev.1405+70c6a9fba

Steps to Reproduce and Observed Behavior

With this repro.zig:

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

pub fn main() anyerror!void {
    const input_file = try std.fs.cwd().openFile("repro.zig.gz", .{});
    var input_buffer: [4096]u8 = undefined;
    var input_reader = input_file.reader(&input_buffer);

    var buffer: [flate.max_window_len]u8 = undefined;
    var decompress: flate.Decompress = .init(&input_reader.interface, .gzip, &buffer);

    const length = try decompress.reader.takeInt(u16, .big);
    std.debug.print("length: {d}\n", .{length});
}

Run it on itself compressed:

$ gzip -k repro.zig

$ zig run repro.zig
error: EndOfStream
zig/std/compress/flate/Decompress.zig:473:17: 0x1022aa5e3 in streamInner (repro)
        .end => return error.EndOfStream,
                ^
zig/std/compress/flate/Decompress.zig:251:17: 0x1022a9a0f in streamFallible (repro)
                return error.EndOfStream;
                ^
zig/std/compress/flate/Decompress.zig:173:21: 0x1022aa31f in streamIndirectInner (repro)
        else => |e| return e,
                    ^
zig/std/compress/flate/Decompress.zig:244:5: 0x1022b99a7 in streamIndirect (repro)
    return streamIndirectInner(d);
    ^
zig/std/Io/Reader.zig:1070:56: 0x1022a4e83 in fillUnbuffered (repro)
            error.ReadFailed, error.EndOfStream => |e| return e,
                                                       ^
zig/std/Io/Reader.zig:1049:5: 0x1022a3e6f in fill (repro)
    return fillUnbuffered(r, n);
    ^
zig/std/Io/Reader.zig:488:5: 0x1022a2307 in peek (repro)
    try r.fill(n);
    ^
zig/std/Io/Reader.zig:536:20: 0x1022a1d63 in take (repro)
    const result = try r.peek(n);
                   ^
zig/std/Io/Reader.zig:553:13: 0x1022a1867 in takeArray__anon_19311 (repro)
    return (try r.take(n))[0..n];
            ^
repro.zig:12:20: 0x1022a14d3 in main (repro)
    const length = try decompress.reader.takeInt(u16, .big);
                   ^

Note, if you instead make an 8mb file and compress it, and run this repro it gets a different error:

$ mkfile -n 8m foo

$ gzip foo

$ mv foo.gz repro.zig.gz

$ zig run repro.zig
error: ReadFailed
zig/std/compress/flate/Decompress.zig:480:27: 0x102d49957 in writeMatch (repro)
    if (w.end < distance) return error.InvalidMatch;
                          ^
zig/std/compress/flate/Decompress.zig:444:17: 0x102d40b07 in streamInner (repro)
                try writeMatch(w, length, distance);
                ^
zig/std/compress/flate/Decompress.zig:262:13: 0x102d3d9cb in streamFallible (repro)
            return error.ReadFailed;
            ^
zig/std/compress/flate/Decompress.zig:173:21: 0x102d3e31f in streamIndirectInner (repro)
        else => |e| return e,
                    ^
zig/std/compress/flate/Decompress.zig:244:5: 0x102d4d9a7 in streamIndirect (repro)
    return streamIndirectInner(d);
    ^
zig/std/Io/Reader.zig:1070:56: 0x102d38e83 in fillUnbuffered (repro)
            error.ReadFailed, error.EndOfStream => |e| return e,
                                                       ^
zig/std/Io/Reader.zig:1049:5: 0x102d37e6f in fill (repro)
    return fillUnbuffered(r, n);
    ^
zig/std/Io/Reader.zig:488:5: 0x102d36307 in peek (repro)
    try r.fill(n);
    ^
zig/std/Io/Reader.zig:536:20: 0x102d35d63 in take (repro)
    const result = try r.peek(n);
                   ^
zig/std/Io/Reader.zig:553:13: 0x102d35867 in takeArray__anon_19311 (repro)
    return (try r.take(n))[0..n];
            ^
repro.zig:12:20: 0x102d354d3 in main (repro)
    const length = try decompress.reader.takeInt(u16, .big);
                   ^

Expected Behavior

It should work?

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions