ec-image: bound the animation budget tests by bytes, not by wall clock
The WebP budget test asserted `elapsed < 2000 ms` and failed on a server
with 3.894534671s. That clock was never measuring the property the test
exists for. The decode is refused once the running total crosses
max_total_alloc; what the test protects is that the refusal happens
before decode_frames clones the whole canvas once per ANMF chunk. The
cost of a refused decode is a deterministic function of the budget and
the canvas size -- wall time is the host's memcpy bandwidth for a fixed
~4 GiB of traffic, which is exactly what differed between the hosts.
Measured, same input, 15 runs each: release 0.747/0.759/0.893 s (min/med/
max), debug 0.774/0.779/0.821 s, server 3.895 s. A 5x spread with
byte-identical decoder work. The existing 2000..3000 ms rerun escape
hatch does not help: 3.895 s falls outside the rerun window.
Replace it with a thread-local counting global allocator in the test
binary and bound the work in bytes against the decoder's own
max_total_alloc. The ceiling is not a fitted constant: it is the limit
the guard enforces, so "refused at the total budget" and "allocated no
more than the total budget" are the same statement.
Each budget test now decodes both a 64-frame and a 4096-frame file and
bounds both, so the cost cannot grow with the attacker's frame count --
a guard spent per input frame, or after the clone instead of before it,
is caught here, and no clock could tell those apart.
Red proof: moving budget.spend from before the clone to after it (one
canvas clone too many) reds on the byte bound at 5120024246 bytes. The
same mutation measures 1.006 s median through the old clock and would
have passed -- that is what decides it. Under load (16-40 spinners plus
direct-write memory hammers, load average 46) decode elapsed reaches
2.42-9.34 s, reproducing the server condition locally, while the new tests
stay green at 6.94-13.81 s per run.
Same class swept in the same file: the GIF budget test's 5 s ceiling, the
60000x60000 GIF frame's 100 ms ceiling, and the LZW bomb's 1 s ceiling
all become byte bounds (measured 4.096 GB, 421 B, and far under 1 MiB
respectively).
The tally is per-thread rather than a global atomic: cargo test runs
these in parallel, and a shared counter summed concurrent decodes
together (reported 6144529702 for a decode that allocates 4096023126).
cargo test -p ec-image scoped green: fuzz 18, differential 19,
real_library 2.