An MPEG audio codec in Zig that decodes Layers I, II and III and encodes Layers II and III.

Fuzz the Layer III encoder, and test what structure cannot show

The target added with the encoder checked that its output was well formed and nothing else, which is exactly the shape of assurance the Layer III fault defeated: those frames had correct sizes, parseable side information, exact Huffman data and the right number of finite samples, and carried noise. A contract about structure says nothing about whether the structure still means anything. So the target now also encodes a tone and insists it comes back. Not at any particular quality -- a signal-to-noise ratio is the wrong measure for a coder that deliberately discards what cannot be heard, and Layer II at 192 kbit/s in stereo has only about 13 dB of ceiling to begin with, so a bar set near what a good encode reaches fails on settings that are behaving perfectly. A 300,000 round soak made that point by finding a legitimate 7.89 dB case against a bar of 10. The bar is now four decibels and means what it says: the signal is still there rather than destroyed, and destruction reads as a fraction of one. Three gaps in the target itself, each found by looking rather than guessing: The tone restarted at phase zero every frame, so a run of them was a sequence of discontinuities rather than a signal, and nothing could have been measured across it. It is now continuous, and a fundamental with two harmonics rather than a bare sine -- one sine occupies a single scalefactor band and leaves the loops nothing to trade off, so an encoder can be badly wrong and still get it right. The shape and the layer were advancing together. With six shapes and the layer alternating by round parity, the two were locked: even-numbered shapes only ever met Layer II and odd-numbered ones only Layer III, so half the pairings never occurred and the tone never met Layer III at all. The layer now advances once per pass over the shapes. And the frames were being generated one at a time into the same buffer, so the input was gone by the time the output arrived. The whole run is built first, which is what makes comparing them possible. The sharp guards for the original fault live beside the code instead, where they can aim at it: one checks that a quantizer step too small to code is refused rather than clamped, and one rebuilds a granule from what the loops chose and insists it still resembles the spectrum it came from. Both fail when the clamp is put back -- verified by putting it back -- and the fuzz target does not, because its tone is an easier thing to code than the signal that first exposed it. Breadth and aim are different jobs and it is worth being clear about which is which. Campaigns run clean: 300,000 rounds in ReleaseSafe and 30,000 in Debug. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Aj95dBZhkUtaGfEW8ZXbHx


Author
Co-author Claude Opus 5 (1M context) Date Commit Parent f998fd77
+263 -22
3 changed files
+263 -22
3 changed files