Something went wrong. Try again.
Sans-I/O image codecs for z2d surfaces: BMP, PNG, JPEG, GIF, TGA, XBM, XPM, Netpbm, PCX, ICO and WebP, with an optional sandbox for decoders
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! A standing reproducer for a panic in Zig 0.16.0's inflater.//!//! Thirty-two bytes of malformed zlib, handed straight to//! `std.compress.flate.Decompress`. No part of this library is involved://!//! ```console//! $ zig run tools/std_flate_panic.zig//! thread N panic: reached unreachable code//! .../std/Io/Reader.zig:546:11: in toss//! assert(r.seek <= r.end);//! .../std/compress/flate/Decompress.zig:548:17: in tossBits//! ```//!//! It matters here because `png.zig` inflates `IDAT` with that decompressor,//! so a malformed PNG can panic a program that decodes it — and a panic//! cannot be caught. The same bytes reached through the PNG decoder hit a//! second, different site, `Writer.unreachableRebase` by way of//! `writeBytePreserve`, so there is more than one reachable panic in there.//!//! The fuzz loop found it, and `src/sandbox.zig` has a test showing that//! `sandbox.decode` turns it into `error.DecoderCrashed` rather than a dead//! process — which is the whole reason that module exists.//!//! Delete this file when the standard library is fixed.
const std = @import("std");const flate = std.compress.flate;
pub fn main() !void { const compressed = "\x78\x03\x9c\x63\x48\x60\x4a\xc0\x60\x00\x00\x03\xc6\x01\x21\x68\xd1\x59\xb8\x51\x00\x00\x00\x00\x49\x45\x4e\x21\xae\x42\x26\x82"; var src: std.Io.Reader = .fixed(compressed);
var window: [flate.max_window_len]u8 = undefined; var d: flate.Decompress = .init(&src, .zlib, &window);
var out: [64]u8 = undefined; const n = d.reader.readSliceShort(&out) catch |err| { std.debug.print("readSliceShort: {t}\n", .{err}); return; }; std.debug.print("inflated {d} bytes\n", .{n});}