pub fn check_decode_truncation_series<D>(dec: D, valid: &[u8]) -> Conformancewhere
D: DecoderConfig + 'static,Expand description
A truncated (incomplete) input is categorized as incomplete client data — never mis-attributed as an internal bug, an OOM, an I/O error, or a caller fault — and never panics or silently decodes.
This enforces the one part of the ErrorCategory taxonomy that IS broadly
distinguishable: whatever a codec’s exact error, cutting a known-good image
short must land in the incomplete-input set
(UnexpectedEof
is ideal, but the rest of the image-bytes-origin Image arm
(Malformed / Unsupported)
is tolerated because a truncated prefix can genuinely look malformed). It catches the real bug class
where a codec reads a length field out of truncated data and OOMs, or funnels a
truncation into Internal — a 5xx for a 4xx-class
client error.
valid is a KNOWN-GOOD encoded image the codec supplies (at least a few bytes).
The check builds a deterministic series of prefixes and, for each, runs a full
decode through the dyn-erased boundary —
DynDecodeJob::push_decode into a
throwaway sink. That is the dyn full-decode path, so the pixel body is
actually read and body truncation is exercised, not just the header a probe
would parse. Each decode is wrapped in catch_unwind
so a codec panic on truncated input becomes a named failure, not a process abort.
Every offending offset is collected and reported together.
Per offset n of len:
- panic → failure (truncated input must never panic).
Ok(decode succeeded) whenn <= len/4(header/early region) → failure: a truncated valid image must not silently decode. Forn > len/4a success is tolerated (trailing-marker / already-complete-payload leniency).Err→ the erasedErrorCategoryis read back: an incomplete-input category passes; any other category fails, naming the offset. If the category did not survive erasure at all, the codec is Pattern A (native-enumtype Error, notAt<CodecError>) — reported once, exactly ascheck_decode_error_envelopereports it.
Like the envelope checks, this is opt-in and NOT part of check_all: the
testkit’s own reference codec is a Pattern-A foil that fails
it on the erased path, while the internal minimal envelope exemplar passes (its
truncations classify as MalformedImage).