edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
Lane vp8guards: malformed VP8 cannot panic the decoder
Base: main at 95bc8a76. Branch lane/vp8guards, worktree ~/.cache/wt/vp8guards.
Goal
DONE.md "ec-vp8 decode": malformed VP8 input must not panic the decoder in release
builds. Malformed input now yields ec_core::Error::corrupt, or the decode returns
normally.
What changed
- Loop filter bounds (
crates/ec-vp8/src/loopfilter.rs).filter_frame_exandfilter_framenow returnResult<()>. The geometry check (plane lengths, strides,mb_infolength) is a real check, done once per frame and returned asError::corrupt. Thedebug_assert!s that guarded the edge helpers are gone. The per-rowtry_into().unwrap()loads are replaced bycopy_from_slice. Every tap an edge reads lies inside the span the frame check validates (see the comment on the check), so no per-pixel test is needed. - Intra panics (
crates/ec-vp8/src/intra.rs).predict_block,predict16,predict8andpredict4returnResult. The twopanic!arms areErr(Error::corrupt(..)). The error propagates with?throughreconstruct_intra_mbandreconstruct_inter_mbtodecode. - Other reachable panics in ec-vp8:
mc.rs: the reference read origin was guarded only bydebug_assert. An unclamped split MV could index past the bordered plane. Newclamp_read_originbrings the origin back to the nearest in-range position, once per block. For conforming streams the origin is always in range, so output is unchanged. Clamped reads land in border replication, which gives the same samples.decode.rs:expecton the key-frame dimensions and on the reference slot becameError::corrupt.run_loopfilterpropagates itsResult.- Left as-is, because no input can reach them:
unreachable!inmodes.rs(tree-produced modes),ymode_as_bmodeindecode.rs,mc.rsbwmatch,bool.rsencoder carry, andi32::try_from(col).unwrap()inmodes.rs.
- Clippy (
--all-targets -D warnings). Now clean. Fixes were mostly mechanical (div_ceil,is_multiple_of,clamp,contains,as_chunks). Index loops over parallel arrays and too-many-argument C-port signatures carry#[allow]with a reason comment. - New test
crates/ec-vp8/tests/malformed_no_panic.rs. Each of the 12 IVF fixtures is decoded truncated at 10 positions and with 50 single-byte corruptions (fixed splitmix64 seed0x5EED_0F08). Each decode runs undercatch_unwind. The test does not depend on the decode result, only on the absence of a panic. - Infrastructure fix
scripts/remote-run.sh. The sync exclude was--exclude=/fixtures/(directory form). It copied the worktree'sfixturessymlink, which points at a path that does not exist on the server, so every fixture test failed with "fixtures missing". The exclude is now--exclude=/fixtures. The stale symlink was removed on both hosts. The hosts' own~/fixtureslink is recreated by the existingln -sline.
Test-only changes: intra tests that expected a panic now assert is_err(). The
filter_frame test calls now unwrap().
Verify
scripts/remote-run.sh vp8guards -- cargo clippy -p ec-vp8 --all-targets -- -D warnings: clean (exit 0).EC_REQUIRE_FIXTURES=1 scripts/remote-run.sh vp8guards -- cargo test -p ec-vp8 --release: all pass (exit 0).- lib unit tests: 57 passed
header_parse: 4 passedkeyframe_exact: 4 passed (includes the WebP still)malformed_no_panic: 2 passed (about 13 s)stream_exact: 3 passed (includesdecode_stream_matches_ffmpeg_on_every_fixture, byte-exact on all 12 fixtures)
- Check that the new test has teeth: on the pre-change
src/it fails with 2 panicking inputs out of 600 (altref-160x96.ivfcorruption 22,clip-obs-320x192.ivfcorruption 43). With the change it passes.
Left
- The no-panic guarantee is empirical for ec-vp8's decode path. The test covers 600 deterministic inputs, not every byte position. A property-based or fuzz harness would be stronger.
- The reachable-panic audit covered
panic!,unreachable!,unwrap,expectanddebug_assert-guarded indexing in ec-vp8src. Unguarded indexing with input-derived indices that is not in those forms was not audited line by line.