saiz/saio/hvcc: bound Vec::with_capacity on counts#162
Conversation
Three more `Vec::with_capacity` sites pass a count read straight from input as the capacity argument, with no upper bound: - `saiz` `sample_count` (`Vec<u8>`, `u32`): worst case ~4 GiB upfront. - `saio` `entry_count` (`Vec<u64>`, `u32`): worst case ~34 GiB upfront for v1 (8 bytes/entry). - `hvcc` `num_nalus` (`Vec<Vec<u8>>`, `u16`): worst case ~1.5 MiB upfront (24 bytes per `Vec<u8>` slot). Same defensive idiom as kixelated#157: pre-flight reject counts that cannot possibly fit in the remaining buffer (`count > buf.remaining() / N`, where N is the per-element minimum), then cap the upfront reservation. - saiz/saio: cap at 4096 to match `trun.rs` — covers typical CMAF segments (hundreds to low thousands of samples) without reallocating. - hvcc: cap at 64 — real HEVC arrays hold a handful of VPS/SPS/PPS/SEI entries, so 4096 would be well past anything realistic. Adds regression tests pinned to `Error::OverDecode` (the wrapper that `Atom::decode_maybe` produces from `Error::OutOfBounds`). Closes kixelated#156.
WalkthroughTwo decoder modules add validation to prevent oversized vector allocations. The SAIZ and SAIO decoders pre-validate 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
These public items in the touched files lacked docstrings, dragging the diff's docstring coverage below the 80% threshold the review bot checks against. Add minimal spec references matching the existing docstring style on `Saiz` / `Saio`.
Closes #156. Follow-up to #157.
Three more
Vec::with_capacitysites pass a count read straight from input as the capacity argument, with no upper bound:saizsample_count(Vec<u8>,u32): worst case ~4 GiB upfront.saioentry_count(Vec<u64>,u32): worst case ~34 GiB upfront for v1 (8 bytes/entry).hvccnum_nalus(Vec<Vec<u8>>,u16): worst case ~1.5 MiB upfront (24 bytes perVec<u8>slot).Fix
Same idiom as #157: pre-flight reject counts that can't fit in the remaining buffer (
count > buf.remaining() / N, where N is the per-element minimum), then cap the upfront reservation.trun.rs. Covers typical CMAF segments (hundreds to low thousands of samples) without reallocating.Tests
Three regression tests pinned to
Error::OverDecode(the wrapperAtom::decode_maybeproduces fromError::OutOfBounds). All 210 existing tests still pass.Test plan
cargo test --all-featurescargo clippy --all-targets --all-features -- -D warningscargo fmt -- --check