Skip to content

Wuffs (Wuffs, C) ​

A memory-safe, hermetic language for "Wrangling Untrusted File Formats Safely", with a standard library of image, compression and checksum codecs written in it and transpiled to one C file; the catalog's reference for suspendable, allocation-free, hostile-input-safe decoding and for what a binary description format would have to express to describe a real decoder.

FieldValue
LanguageWuffs (compiler and tools in Go), transpiled to C99 with C++ auxiliary code
LicenseApache-2.0 OR MIT (LICENSE, LICENSE-APACHE, LICENSE-MIT; the changelog records the change from Apache-2.0 alone)
Repositorygoogle/wuffs
Revision read4be865da258c4b5e6d3e716fd4f36be016496a46 (October 21, 2026; the snapshot version macros report WUFFS_VERSION_STRING "0.0.0+0.00000000" and pre-release label "unsupported.snapshot"; the release README names v0.3 as the latest stable version)
Documentationdoc/ (language and library overviews), doc/note/ (short design notes), doc/std/ (API categories), doc/benchmarks.md
CategoryFormats: safe codec language and standard library
TierA
Last reviewedNovember 15, 2026

IMPORTANT

What was run. The verifier reran claims marked verified against the pinned snapshot and test/data/ using GCC 16.2.0 and LDC 1.43.0. Full PNG decoding from D passed with both a GCC implementation and an ImportC-built scalar implementation. The probes lived under /tmp/wuffs-verifier, using nix develop /home/petar/code/repos/mine/sparkles-images -c; they are not CI fixtures. Other upstream claims were checked with git show. Throughput figures are upstream measurements from doc/benchmarks.md, not measurements made here.


Overview ​

What it solves ​

Wuffs targets parsers exposed to malicious input. Its language checks safety in three bug classes at compile time, eliminating those run-time checks in inner loops. The README states the claim:

"However, unlike hand-written C, Wuffs the Language is safe with respect to buffer overflows, integer arithmetic overflows and null pointer dereferences. A key difference between Wuffs and other memory-safe languages is that all such checks are done at compile time, not at run time. If it compiles, it is safe, with respect to those three bug classes."

The standard library (std/) holds the codecs. The image decoders are BMP, ETC2, GIF, Handsum, JPEG (baseline and progressive), Netpbm, NIE, PNG (with APNG), QOI, Targa, ThumbHash, VP8, WBMP and WebP (lossless VP8L and, through std/vp8, lossy). The compression decoders are bzip2, deflate, gzip, lzip, LZMA, LZW, XZ and zlib; the hashers include Adler-32, CRC-32, CRC-64, SHA-256 and xxHash; std/json and std/cbor are token decoders. There is no encoder in std/ at this revision. According to the README, Wuffs' GIF decoder has shipped in Chrome since June 2021 (milestone M93); Skia's SkWuffsCodec is the integration (see Skia).

Design philosophy ​

Wuffs gives up power to make proof easy. The hermeticity note lists what the language lacks: "no mutable global variables", "no unsafe keyword", "no FFI", "no user-supplied callbacks", "no system calls", "no allocation or de-allocation of memory" and "no panicking or throwing exceptions", and ends "with less power comes easier proof of safety". Ownership is one rule (memory-safety.md):

"When a Wuffs decompressor reads from or writes to a buffer, that buffer has to be passed on every call, instead of being passed once during initialization and saved to a field. There is no ambiguity about whether the caller or callee should free some memory, even when encountering an error. It's always caller-owned and callee-borrowed."

The I/O consequence is Sans I/O: the library computes, the caller reads files and sockets, so the same decoder serves synchronous and asynchronous programs (README). The cost is admitted: programs "take longer for a programmer to write, as they have to explicitly annotate their programs with proofs of safety" (README). The proof checker is deliberately simple: "a proof checker, not an SMT solver or automated theorem prover ... the Wuffs compiler is fast (and dumb) instead of smart (and slow)" (assertions.md).


How it works ​

Proof by facts, refinements and intervals ​

Every index, slice and arithmetic expression must be proved in range. Three sources feed the proof (bounds-checking.md): refinement types such as base.u32[..= 100], facts created by if and while conditions or by assignment (facts.md), and integer interval arithmetic over expressions (interval-arithmetic.md). A masked index such as a[expr & 1023] on an array[1024] base.u8 is in bounds by interval arithmetic alone; a slice index needs a dynamic fact from a condition. Loops are not inferred: "Wuffs simply requires the programmer to write exactly what the situation is, before and after the loop" with pre, inv and post clauses (facts.md). Facts that the checker cannot derive are stated with assert ... via "axiom", where the axiom is a named rule from a fixed list (axioms.md). Overflow uses the same machinery; wrapping and saturating arithmetic are explicit operators (~mod+, ~sat-). The README's own example of a rejected one-line edit prints the failing interval and the facts in scope (README).

Effects, coroutines and statuses ​

Functions are pure, impure (!) or coroutines (?); sub-expressions must be pure (effects.md). A coroutine may suspend by returning a suspension status; "Calling that function again will resume that function where it left off" (coroutines.md). Coroutines are methods, their state lives in the receiver struct, and they may call other coroutines but not recursively. Crossing a suspension point "drops any facts involving this or args", so proofs must be re-established after each one.

A status is a statically allocated C string whose first byte gives its category (statuses.md): ok (null), @ note ("completed, unsuccessfully", for example "@end of data"), $ suspension ("not completed, but can be re-tried") and # error ("not completed, permanently"). Errors are sticky: later status-returning calls return "#disabled by previous error". Ordinary I/O uses "$short read" when the source is empty and "$short write" when the destination is full (coroutines.md); metadata passthrough also uses "$even more information" (metadata.md).

The transpiler lowers coroutines to a switch over a resume point, Duff's-device style (fundamental-private.h):

c
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
  coro_susp_point = n;                            \
  case n:;

A multi-byte read that straddles a suspension accumulates bytes in a per-coroutine scratch field in the receiver; in the generated zlib header read, a 2-byte read_u16be takes a fast peek_u16be__no_bounds_check path when two bytes are available and otherwise loops one byte at a time, suspending with short_read and resuming at the same case (generated zlib read in the snapshot, available as a raw download from decode_zlib.wuffs).

I/O buffers, readers and writers ​

An io_buffer is a byte slice plus ri, wi, pos and closed (io-public.h; io-input-output.md), with the invariant ((0 <= ri) and (ri <= wi) and (wi <= len)). pos makes the buffer a sliding window over a stream, so pos + ri is an absolute stream position; compaction moves unread bytes to the front without changing it. closed separates "need more bytes" from truncation (io-input-output.md): with fewer bytes than a read needs, an open buffer suspends and a closed one is an error. Wuffs code sees a buffer only as a base.io_reader or base.io_writer, and "ri and wi will never be decremented ... to be less than the initial values at the time of the call" (io-input-output.md). Two block constructs adapt buffers inside Wuffs code: io_bind presents a slice as a reader or writer, and io_limit caps how much of a reader a callee may consume. Readers expose mark(), since(mark:) and count_since(mark:), which return the bytes or count consumed since a mark; the checksum code below is built on them.

Token streams are the non-pixel output form: a token is a uint64_t with a 16-bit length, a continued bit and 47 value bits, and "The tokens partition the bytes" (tokens.md). The JSON decoder is a pull tokenizer for this reason.

The image decoder interface ​

Every image decoder implements base.image_decoder (image-decoders.md); the core methods are:

text
decode_image_config?(dst: nptr image_config, src: io_reader)
decode_frame_config?(dst: nptr frame_config, src: io_reader)
decode_frame?(dst: ptr pixel_buffer, src: io_reader, blend: pixel_blend,
              workbuf: slice u8, opts: nptr decode_frame_options)
workbuf_len() range_ii_u64
restart_frame!(index: u64, io_position: u64) status
set_quirk!(key: u32, value: u64) status
set_report_metadata!(fourcc: u32, report: bool)
tell_me_more?(dst: io_writer, minfo: nptr more_information, src: io_reader)

The canonical sequence is DIC, then pairs of DFC and DF, then a final DFC that returns "@end of data" (call sequence). A still image is the case N = 1. Calls may be skipped and are then made implicitly: calling DF first runs DIC and DFC #0; calling only DFC in a loop counts frames while skipping, not decompressing, pixel data. A private call_sequence byte tracks the state (0x00, 0x20, 0x40, 0x60, with 0x10 for metadata detours and 0x08 for restarts) and rejects out-of-order calls with "#bad call sequence". restart_frame jumps to frame i once the caller has positioned the reader at the io_position that frame's frame_config recorded.

Memory is negotiated, not taken. DIC returns dimensions and a pixel format; the caller allocates the pixel buffer or reports the image as too large to decode (memory-safety.md); workbuf_len() returns an inclusive range of scratch bytes. For PNG the range is exact, height * (1 + bytes_per_row), with non-interlaced PNG inflated as a whole before unfiltering; Adam7 is inflated and unfiltered one pass at a time (decode_png.wuffs, decode_ihdr, workbuf_len). JPEG's range has a lower bound of 0 when the lower-quality option is set and the file is not progressive (sof_marker < 0xC2) (decode_jpeg.wuffs). The decoder object itself is opaque in C: callers ask sizeof__wuffs_png__decoder() and call wuffs_png__decoder__initialize with that size and WUFFS_VERSION, and there is no destructor (initialization.md).

Decoded pixels go through the pixel swizzler, which converts and composites from the codec's source format to a supported destination format and blend the caller chose (wuffs_base__pixel_swizzler__prepare selects one function pointer per destination format, source format and blend; pixconv-submodule-regular.c). The swizzler is hand-written C in the base package, not Wuffs; the base README says pixel and string conversion "sometimes require programming language features (e.g. function-pointer typed variables, SIMD acceleration) that are not yet available in Wuffs-the-language".

A PNG decode, end to end ​

The PNG decoder shows every mechanism at once.

  • Magic and header as numbers. The 8-byte signature is read as one little-endian u64 and compared with '\x89PNG\x0D\x0A\x1A\x0A'le; the next 8 bytes must equal '\x00\x00\x00\x0DIHDR'le, and Apple's CgBI variant is named and refused (decode_png.wuffs).
  • Checksums across suspensions. Before each critical chunk body the decoder resets crc32 and feeds the 4 type bytes; the body is parsed in a loop that marks the reader, calls the sub-parser, hashes args.src.since(mark: mark), and only then yields on suspension. The CRC therefore covers exactly the consumed bytes however the input was split. Critical chunks are verified; ancillary chunk CRCs are skipped; the source contrasts this with libpng's "warns and discards" default, which also continues image decoding (decode_png.wuffs).
  • Validation in the reader. decode_ihdr rejects zero or > 0x7FFF_FFFF dimensions as "#bad header" and anything above 0xFF_FFFF as "#unsupported image dimension", checks depth, colour type, compression, filter and interlace bytes, and derives overall_workbuf_length (decode_png.wuffs).
  • Decompression inside chained chunks. decode_pass binds the work buffer as a writer, wraps the source in io_limit (io: args.src, limit: chunk_length), and runs zlib.transform_io? inside it. When the chunk is exhausted with zlib still wanting input, it verifies an IDAT chunk's CRC, reads the next chunk header, insists on another IDAT (or fdAT with the next animation sequence number), resets the CRC for IDAT (ancillary fdAT CRCs are skipped) and continues the same zlib stream. A stream that ends with chunk bytes left is "#too much data", one that fills less than the work buffer is "#not enough data" (decode_png.wuffs).
  • Two checksums, two directions. PNG's CRC-32 covers compressed input (src.since); zlib's Adler-32 covers decompressed output, hashed from args.dst.since(mark: mark) after each deflate call (decode_zlib.wuffs).
  • Policy as quirks. WUFFS_BASE__QUIRK_IGNORE_CHECKSUM skips both (quirks.md); PNG forwards it to its inner zlib decoder.

Verified with the scratch program on test/data/hippopotamus.regular.png (36 by 28, RGB, one IDAT of 2,086 bytes): a whole-buffer decode, a decode fed 1 byte at a time through a 16-byte compacted source buffer (40 DIC suspensions, 2,090 DF suspensions) and a 7-byte feed all produced the same pixel hash, and workbuf_len() was [3052..3052] (28 × (1 + 36 × 3)). The Adam7 file hippopotamus.interlaced.png decoded to the same pixel hash under both feeds. sizeof__wuffs_png__decoder() was 44,648 bytes.

What a binary description format would have to express ​

This is the Q4 question asked of sparkles:wired. Each row is a behaviour a Wuffs decoder implements in code, with where it is shown; the last column is the Flat draft's position as recorded in the wired baseline (G2 to G6). The verifier checked the named rules, byte order, offset widths and O9 at the baseline's pinned draft 8a454ce151c23b3608467cf8e19821678583ecb3. "Not described" records the baseline's scope, not a demonstrated impossibility.

RequirementWuffs evidenceFlat draft per the baseline
Fixed-width integers with per-field byte order; magic values compared as numbersread_u32be, read_u64le, 'IHDR'le constants (PNG)fixed integers yes; byte order fixed at compile time (G5)
Bit fields that cross byte boundaries, LSB-first (deflate) and MSB-first (JPEG), with refill state kept between callsbits, n_bits fields (deflate); bitstream_bits, bitstream_n_bits (JPEG)only ranges inside one leaf of at most 64 bits (WFL27); excluded by O9 (G2)
Field predicates and cross-field arithmetic checkszlib x % 31, compression method and window (zlib); stored-block LEN + NLEN == 0xFFFF (deflate)checks on the decoded fixed part (WFL28)
A length prefix that scopes a sub-reader whose bytes another decoder consumesio_limit (io: args.src, limit: chunk_length) around zlib.transform_io? (PNG)not described in the baseline
Checksums over a byte range, on compressed input or on decompressed output, computed incrementally across suspensionsCRC-32 over type plus body via mark/since (PNG); Adler-32 over dst.since (zlib)a check cannot see payload bytes (WFL20, G4)
One logical stream chained across several framed chunks, per-chunk checksums reset, decompressor state continuingIDAT…IDAT, fdAT sequence numbers (PNG); GIF sub-blocks of at most 255 bytes ending in a zero length (GIF)sequential self-sized arrays (WFL33); no stream continuation
Escape removal before the bit reader sees dataJPEG 0xFF 0x00 unstuffing, fill bytes, marker detection and implicit zero padding into a 2 KiB buffer (JPEG)not described
Suspendable reads at any field, including multi-byte fields split across buffers, and a truncation outcome distinct from "need more"scratch accumulation (generated zlib), "$short read" versus closed (I/O)truncated is terminal; no short-read status (G3)
Absolute stream positions for seeking and restartspos + ri, restart_frame(index, io_position) (I/O, call sequence)offsets of at most 32 bits (G5)
Ordering rules between chunk kindsWebP variant bits track VP8X, ICCP, ANIM, ANMF, ALPH order (WebP); PNG acTL/fcTL/IDAT/fdAT rules (PNG)not described
Output-size contracts derived from header fieldsworkbuf_len = height * (1 + bytes_per_row) (IHDR); "too much" and "not enough" data errors (PNG)budgets are traversal bytes and depth (G8)
Metadata reported as stream ranges or as transformed bytesraw passthrough ranges for eXIf, zlib-inflated iCCP (metadata.md, PNG)not described
Acceptance policy switchesquirks, including IGNORE_CHECKSUM (quirks.md)not described

The pattern across the rows is that headers and chunk framing are declarative in shape, while entropy payloads, escapes, stream continuation and checksum placement are code that the framing must hand bytes to and get bytes back from. NIE, Wuffs' own uncompressed format, is the counter-example: a 16-byte header of 4 magic bytes, 4 version-and-configuration bytes (a version byte, a fixed b and two flag bytes) and two little-endian uint32 dimensions, then raw pixels (nie-spec.md); a fixed-layout description covers it whole.


Analysis ​

1. Pixel and memory model ​

A wuffs_base__pixel_buffer is a pixel_config (format, subsampling, width, height) plus up to four planes, each a table_u8 with pointer, width, height and byte stride (image-public.h); see plane and stride. An 8-bit planar sample is at planes[p].ptr + (j * planes[p].stride) + i, and subsampling maps a pixel to a plane sample by a per-plane bias and denominator (pixel-subsampling.md; chroma subsampling). The pixel format is one uint32_t bit field: colour model and channel order, transparency, a big-endian bit, a float bit, a palette bit, the plane count and four 4-bit channel depths (pixel-formats.md). Channels are named "in memory order ... regardless of endianness" (source note; pixel format names). Indexed images keep the palette, always 256 × 4 bytes of non-premultiplied BGRA, in plane 3.

Two findings. First, the format note's worked example names 0x80000565 as BGR 565 (colour nibble 8 is BGR) and then calls the same value 0x40000565 twice (nibble 4 is YCbCr), so the hand-written prose has drifted from the bit layout it explains (pixel-formats.md); the code confirms WUFFS_BASE__PIXEL_FORMAT__BGR_565 is 0x80000565 (image-public.h). Second, the model is 2-D only: no N-D extent, no tiles, and the pixel buffer carries "// TODO: color spaces.". Dimensions are capped at 0xFF_FFFF so that width * height * bytes_per_pixel cannot overflow an i64 (image-decoders.md).

2. Genericity mechanism ​

There are no generics. Polymorphism is by interface: a struct declares implements base.image_decoder, base.io_transformer or base.hasher_u32, and the C form dispatches through a vtable recognised by a vtable_name string pointer (wuffs_base__image_decoder__vtable_name in the snapshot). Pixel format variety is a run-time value resolved once by the swizzler into a function pointer, and CPU variety by choose (section 7). Code size is managed by preprocessor selection: WUFFS_CONFIG__MODULES plus one WUFFS_CONFIG__MODULE__X per package, and an allow-list of destination pixel formats (WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST) that removes swizzler paths (pixconv-submodule-regular.c). The project's own measurements put wuffs-base-pixconv at 56,192 bytes and wuffs-std-png at 54,760 bytes in a clang 11 shared build (binary-size.md). Compared with the static genericity of Boost.GIL or mir, Wuffs keeps one compiled decoder and moves format choice to run time.

3. Colour and metadata ​

Decoders do not manage colour. They report it. By default metadata is skipped; set_report_metadata(fourcc, true) makes a decode call return "@metadata reported", after which tell_me_more describes it in one of three flavours (metadata.md): parsed (small values such as gamma or the eight chromaticity numbers), raw passthrough (a byte range of the input for the caller to route to a separate parser) and raw transform (bytes the decoder must process, for example decompress, before handing over). PNG maps cICP to a parsed 'CICP'be with the four bytes in metadata_x, eXIf to a passthrough range from position() to position() + chunk_length, and iCCP to a zlib-inflated transform (decode_png.wuffs, decode_png.wuffs); see CICP, ICC profile and image metadata. Alpha state is part of the pixel format: non-premultiplied, premultiplied or binary (pixel-formats.md; straight and premultiplied alpha). There is no HDR transfer handling or gain map support. The swizzler does include fixed YCbCr-to-RGB and CMYK/YCCK conversions (pixconv-submodule-ycck.c); these do not apply an ICC profile. The caller must perform profile-based colour management itself.

4. I/O and codec architecture ​

Wuffs is the catalog's clearest example of caller-driven incremental, suspendable decoding: every public decode method is a coroutine over caller-owned io_buffers, so the same object serves a whole file in memory, a pipe read in 4 KiB pieces, or an event loop that refills a buffer on completion. In the push and pull vocabulary the caller pushes bytes in by filling the reader and the decoder pulls within what it is given; neither side blocks. Compression decoders expose one method, transform_io?(dst, src, workbuf), and the I/O suspensions are how such decoders "decompress from arbitrarily long inputs to arbitrarily long outputs with fixed sized buffers" (coroutines.md); example/zcat does so with static buffers under a SECCOMP_MODE_STRICT sandbox (memory-safety.md).

The fast and slow paths split on suspension. Deflate's decode_huffman_fast64! is an impure, non-suspending function that runs only while args.dst.length() >= 266 and args.src.length() >= 8, checking those bounds once per iteration so the body needs no further checks; when either runs short it returns and decode_huffman_slow?, a coroutine, handles the boundary (decode_huffman_fast64.wuffs, decode_deflate.wuffs). The PNG decoder inflates into a work buffer and then filters and swizzles rows (one Adam7 pass at a time), rather than exposing a row-streaming API (decode_png.wuffs). Whole-image inflation for non-interlaced PNG is one reason Tao's PNG article gives for its speed (see the entropy-codecs thread).

Truncation is reported where it is detected. Verified: decoding hippopotamus.regular.truncated.png with closed set at end of input returned "#deflate: truncated input", the inner decoder's status passed through PNG unchanged.

5. Hostile input and safety ​

The hostile-input defence is primarily the language: bounds, overflow and null checks proved at compile time, no allocation, no syscalls. Three limits on that claim are written down in the repository:

  • Not everything in the C file is Wuffs. The base package (I/O helpers, pixel conversion, string conversion) and the C++ wuffs_aux helpers are hand-written; the auxiliary-code note says "unlike code written in the Wuffs language, its memory-safety is not enforced by the Wuffs toolchain" (auxiliary-code.md). The swizzler, which every image decode calls, is in that category and has its own fuzzer (fuzz/c/std/pixel_swizzler_fuzzer.c).
  • Uninitialised memory is opt-in risk. WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED skips zeroing internal buffers; the compiler then refuses refinements on those fields, but reading uninitialised bytes "is not a bug class that the Wuffs compiler eliminates" (initialization.md).
  • Termination and time are out of scope. "Wuffs functions are not guaranteed to halt" (hermeticity.md); there is no work budget, so a caller can stop between calls, but cannot enforce a time budget within a call through this API.

Logical impossibilities that the prover cannot see are written as explicit "#internal error: ..." returns, and the fuzz harness turns those into crashes: "As of November 2019, this has not yet found any memory-safety bugs in Wuffs" (fuzzing.md); fuzzlib.c calls intentional_segfault() on any "internal error:" message and on a short read from a closed reader (fuzzlib.c). Resource limits are structural: the 24-bit dimension cap, exact work-buffer sizes, and fixed-size internal arrays (deflate history of 0x8000 + 257 bytes, GIF's 4,096-byte compressed staging array).

Verified with the scratch program: flipping one bit of the IHDR CRC gave "#png: bad checksum", and the same file decoded with QUIRK_IGNORE_CHECKSUM; flipping a bit of the final IDAT CRC gave "#png: bad checksum"; setting the IHDR width to 0x0100_0000 gave "#base: unsupported image dimension", reported from decode_ihdr before the CRC comparison.

6. Allocation and ownership ​

Wuffs code cannot allocate. The caller allocates the decoder (size from sizeof__wuffs_png__decoder(), 44,648 bytes verified, most of it fixed internal arrays), the source and destination buffers, the pixel buffer and the work buffer. Re-initialising resets an object, and "There are no destructor functions. Just free the memory." (initialization.md). The C form adds wuffs_foo__bar__alloc conveniences and wuffs_aux::DecodeImage, which allocate on the caller's side of the boundary and assume synchronous I/O (auxiliary-code.md). This is the same split the image-rs and zune-image decoders approximate with decode_into, but enforced: a Wuffs decoder has no way to retain a pointer to caller memory between calls, because struct fields cannot hold pointers to dynamically allocated memory (memory-safety.md).

7. CPU parallelism and SIMD ​

There is no threading: Wuffs "lacks the capability to create, destroy or otherwise manage threads", and separate objects are safe on separate threads because there is no global mutable state (memory-safety.md). SIMD is in the language. A function marked choose cpu_arch >= x86_sse42 (or arm_neon, x86_avx2, x86_bmi2) can use typed vector values such as base.x86_m128i; a choosy function names the default, and a choose f = [a, b, c] statement picks the first variant the running CPU supports (common_crc32.wuffs, common_up_x86_sse42.wuffs, decode_png.wuffs). In the generated C, the choice is a choosy_up function pointer in the object, set after a wuffs_base__cpu_arch__have_x86_sse42() check. SIMD paths exist for CRC-32 (SSE4.2, ARM CRC32), Adler-32 (SSE4.2, NEON), PNG filters (SSE4.2, NEON), deflate's Huffman loop (BMI2), JPEG's IDCT (AVX2) and swizzler conversions (SSE4.2, AVX2 in pixconv-submodule-x86-avx2.c). WUFFS_CONFIG__AVOID_CPU_ARCH removes all of them.

The project's own numbers (Intel i5-10210U, September 2022, against Debian's libraries; benchmarks.md) show what that buys: PNG decode at 1.55x to 3.16x libpng (PNG table), zlib at 1.53x to 1.70x zlib-the-library and roughly on par with libdeflate (zlib table), deflate below zlib at 1 KiB (0.76x to 0.93x) and above it from 10 KiB (deflate table), and CRC-32 at 9.1x to 14.7x zlib but below libdeflate (CRC-32 table).

8. GPU offload and interop ​

Not applicable: Wuffs has no GPU code and no notion of device memory. Two points bear on Q6 all the same. Because the pixel buffer is caller-owned and described by pointer and stride, a caller can in principle point it at mapped staging memory and decode straight into it (an assessment; not demonstrated here). And std/etc2 decodes ETC1/ETC2 texture data to CPU pixels (its header comment describes both the raw block format and the 16-byte PKM file header): the direction opposite to upload, useful as an oracle for texture work (decode_etc2.wuffs).

9. Temporal, animation and containers ​

Animation is first-class in the image interface: frame_config carries the frame rectangle, duration, disposal, blend mode and the frame's I/O position, and the decoder reports num_animation_loops, num_decoded_frames and a frame_dirty_rect (frame_config fields; image-decoders.md). GIF and APNG support animation; the WebP decoder tracks the VP8X chunk order including ANIM and ANMF (decode_webp.wuffs), but skips their bodies (chunk parser), exposes only frame zero (frame configuration) and returns 0 from num_animation_loops (counters). It does not decode animated WebP frames at this revision. Random access is cooperative: restart_frame plus an I/O position, with the caller performing the seek. Containers are handled inside each package (PNG chunks, RIFF for WebP, GIF blocks); there is no shared container layer. std/vp8 exists for lossy WebP, which "essentially wraps one VP8 key frame"; the WebP README notes "There's no Wuffs WebM package yet" (std/vp8/README.md, std/webp/README.md). NIA, the animated sibling of NIE, is the project's own animation format (nie-spec.md); see container and bitstream.

10. Testing and conformance ​

Each package has a C test file under test/c/std/ that runs as unit tests or, with -bench, as benchmarks; "mimic" tests compare Wuffs' output byte-for-byte with another library's on the same input, which is also how quirks are justified (benchmarks.md, quirks.md). The mimic libraries live under test/c/mimiclib/, one file per family (PNG, GIF, deflate with gzip and zlib, JPEG, WebP, LZMA, bzip2, stb and others). A corpus-wide oracle covers decoded output: script/print-nia-checksums.sh runs example/convert-to-nia over every file in test/data and prints the CRC-32 of each decodable file's NIA output, and build-all.sh diffs that against the committed test/nia-checksums-of-data.txt (207 lines) (print-nia-checksums.sh, build-all.sh). Fuzzing has run on OSS-Fuzz since February 2018 (fuzzing.md), with per-format fuzzers in fuzz/c/std/ and seed corpora listed in seed_corpora.txt. The compile-time checker is itself part of conformance: it fails the build, not a test. The hostile-input thread places this beside verified parsers and differential testing.


Lessons for Sparkles ​

  • Q4. The three-phase API (config, caller allocates, frame) with a declared workbuf_len range maps directly onto Sparkles' standing rules: a decoder struct whose methods are @safe nothrow @nogc, taking caller slices (scope ubyte[] under dip1000) and never storing them, with sizes as size_t. It is the shape font.png already has and ui.png lacks (existing-code baseline, G6 and G7). What does not transfer as-is is the four-category status model: Wuffs separates ok, note, suspension and error, while Expected has two arms. The wired baseline's G3 and its decision 3 record that a suspension status must coexist with Expected (wired baseline); Wuffs is evidence that suspension should be a value, not an error kind.
  • Q4. The description table is the requirement list for the later wired experiment. Of its thirteen rows, fixed integers, field predicates and self-sized chunk sequences have drafted counterparts in Flat; bit streams, escapes, stream continuation across chunks, checksums over payload ranges, suspension and 64-bit positions do not (wired baseline, G2 to G6). Wuffs itself does not describe these declaratively: it writes them as code over a reader with mark, since and io_limit. A description format that framed chunks and handed scoped readers to codec code would cover what Wuffs keeps declarative-shaped; one that tried to describe the entropy layer would be describing a program.
  • Q4. Wuffs' resumption is a generated switch with per-coroutine scratch in the receiver. D has no stackless coroutines; the options on the branch are a hand- or mixin-generated state machine of the same shape, or fibers, which the event-horizon baseline (G6) says cannot migrate between threads. The generated shape needs nothing from a runtime, so it is the one compatible with --better-c, --wasm and Android builds; that compatibility is an inference from the generated C, not a D measurement.
  • Q4, Q8. The fast-path/slow-path split (check "8 bytes in, 266 bytes out" once, then run an unchecked inner loop; fall back to a suspending path at boundaries) is the D answer to "bounds checks cost": slice once per iteration so the compiler, or a single reviewed @trusted lambda, elides per-byte checks. Whether LDC removes the checks in a checked build is a measurement Sparkles has not made (shaders and SIMD baseline).
  • Q8. Three testing devices transfer without the language: byte-exact "mimic" tests against reference libraries; a committed checksum of every decoded file in the corpus, diffed by the build; and fuzzers that crash on any "impossible" status. The last maps onto D assert(0) in a fuzz build. The existing-code baseline's G11 records that Sparkles' oracles are single-purpose (existing-code baseline).
  • Q8. Checksum policy is a quirk: critical PNG chunks are verified and ancillary CRCs are skipped. Wuffs' source compares this with libpng's warn-and-discard policy for bad ancillary CRCs (PNG). Both Sparkles PNG decoders skip all chunk CRCs (existing-code baseline, G1); Wuffs shows verification costs little on one upstream benchmark (837 versus 871 MB/s, verify against ignore, clang 11; PNG table). That result does not establish the cost for every image or CPU.
  • Q1. The pixel buffer (format word, up to four planes, per-plane stride, a subsampling description) is the minimal 2-D model that holds both RGBA and 4:2:0; it is not N-D. The drift found in pixel-formats.md is a small instance of the hazard Sparkles' rule "enum names are wired data" addresses: generate names and documentation from the bit layout, do not hand-maintain both.
  • Q5. "Report, do not convert" is a complete minimum: CICP as four bytes, gamma and chromaticities parsed, ICC and EXIF as ranges or inflated bytes, alpha state in the format. It leaves colour management to a separate layer, which is the question Q5 asks.
  • Q3, Q7. choose is per-function CPU dispatch that stores the selected function pointer in the object for subsequent calls. CRC-32 selects when its state is zero (common_crc32.wuffs). The shaders and SIMD baseline (G5) records that Sparkles repeats dispatch by hand; Wuffs is evidence for one mechanism that every kernel names, with a portable default always present.
  • Q6. Caller-owned, strided pixel memory could let a decoder write directly into CPU-writable GPU staging memory, subject to its format, stride and synchronization requirements. This is an ownership-based assessment, not a demonstrated GPU path. Whether sparkles:vulkan's one upload path can accept it is in the Vulkan baseline.
  • Q9. The release is one C file with per-package macros, a base of shared types and conversion, and one package per codec. That is evidence for a small shared core (buffers, statuses, pixel format, swizzler) under per-format codecs. It also shows where unproved code concentrates: in the shared conversion core. Verified: a full PNG decode from D through ImportC header mode (LDC 1.43.0, implementation built by GCC 16.2.0 with SIMD) matched the C probe's 153761e2 pixel hash and 44,648-byte decoder size. The opaque decoder was allocated with the C size function. The D header wrapper undefines __SIZEOF_INT128__ and __SIZEOF_LONG__ and defines WUFFS_CONFIG__AVOID_CPU_ARCH; NIX_HARDENING_ENABLE was empty. The same decode passed with the scalar implementation compiled through ImportC using those workarounds and WUFFS_IMPLEMENTATION. This establishes neither SIMD implementation compilation by ImportC nor ABI compatibility for every codec. See ImportC C libraries.

Strengths ​

  • Bounds, overflow and null safety proved at compile time, with no run-time checks in the shipped inner loops.
  • Hermetic by construction: no allocation, I/O, globals, callbacks or threads, so the attack surface is the input bytes alone.
  • Every decode is suspendable over caller buffers, with a small, uniform status vocabulary and sticky errors.
  • One image interface for stills and animation, with implicit calls, frame counting without decompression and random access by I/O position.
  • Declared memory needs (workbuf_len ranges, sizeof functions) before any pixel is decoded.
  • Ships as one C99 file with per-package selection; usable without the Go toolchain.
  • Fast on the project's own benchmarks, and backed by mimic tests, a corpus checksum oracle and OSS-Fuzz since 2018.

Weaknesses ​

  • Writing Wuffs is slow; the README says so, and the toolchain's documentation has open TODOs about when facts are removed and what is proved automatically.
  • The pixel swizzler, string conversion and wuffs_aux are hand-written C or C++ outside the proof.
  • No encoders, no profile-based colour management or HDR transfer handling, and no N-D or tiled images.
  • Termination and work are unbounded; a time or work budget is the caller's problem.
  • The roadmap still lists JPEG and WebP decoding as future work, although their decoders exist at this revision: that document lags the code.
  • Consuming the C file from another language's C importer needs workarounds (verified for D ImportC above).

Key design decisions and trade-offs ​

DecisionRationaleTrade-off
Compile-time proof instead of run-time checksSafety without per-access cost in hot loopsProgrammers write facts, invariants and axiom citations; slower to author
Proof checker with named axioms, no SMT solverFast, reproducible compilationMore explicit annotation; the checker proves only what it is told
Hermetic language: no allocation, syscalls, callbacks, threadsTrivial safety against leaks, use-after-free and ambient authorityEvery API is multi-step; convenience layers live outside the proof
Coroutines with I/O suspensions over caller io_buffersArbitrary input and output sizes with fixed memory; works sync or asyncState machines in every receiver; facts about this lost at each suspension point
Status as a static string with a category bytePointer comparison, no allocation, readable in debuggingNo structured error context (offset, field) beyond the message
Config, then caller-allocated pixel and work buffersThe caller can refuse oversized images before allocatingTwo or three calls per frame; work buffer may equal the whole filtered image
24-bit dimension capOverflow-free arithmetic on sizes everywhereImages wider or taller than 16,777,215 pixels are refused
Quirks as numbered set_quirk keysMatch other decoders' behaviour on malformed input; mimic testsBehaviour depends on configuration that must be recorded with results
Pixel conversion in hand-written CFunction pointers and SIMD that the language lackedThe most widely called conversion code is outside the proof
One generated C file with module macrosstb-style integration; no Wuffs toolchain needed by usersA 3.7 MB source file; importers of C headers meet compiler-specific constructs

Sources ​