Repository navigation
Harden unci channel allocation and SPS bit depths (HEIF Heist F7/F10) - #18
Merged
laurenspriem merged 2 commits intoOct 30, 2026
Merged
Conversation
decode_primary_uncompressed_to_channels_internal allocated pixel_count u16 samples per channel from the ispe/uncC geometry before the item payload was extracted, so a lying ispe on a tiny file forced a ~26 GB zero-fill allocation abort under default guardrails. - move the channel allocation after the payload (iloc extraction plus generic-compression decompression) is in hand - reject component bit depths outside 1..=16, the range the u16 sample storage can represent - require the payload to carry at least the minimum sample bits the declared geometry implies (per-component subsampling, ceil dims), so the lying-ispe case fails as MalformedInput instead of allocating - allocate via try_reserve_exact so a pathological-but-consistent geometry yields an error rather than an allocation abort, the pattern the bounded path uses
bit_depth_y()/bit_depth_c() computed 8 + bit_depth_*_minus8 as a plain u8 add, and the lenient parse path read the fields through bounded_ue_u8 truncation, so minus8 values above 8 wrapped and values above 255 truncated into wrong depths. Read both fields as raw ue values and reject anything above 8 on both parse paths; depths are now guaranteed within 8..=16.
Author
|
@codex review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The two small leftovers from the HEIF Heist audit, closing out the vulnerability class (only the F11 default-cap design call would remain).
F7 — unci channel allocation before validation.
decode_primary_uncompressed_to_channels_internalallocatedpixel_countu16 samples per channel straight from the ispe/uncC geometry, before the item payload was even extracted — a lyingispeon a tiny file forced a ~26 GB zero-fill allocation abort under default guardrails. The allocation now happens only after the payload is in hand (post extraction/decompression, both already capped), gated by: component bit depths within 1..=16 (the u16 storage range), and a necessary-condition check that the payload carries at least the minimum sample bits the declared geometry implies (mode-aware: per-component subsampling with ceil dims for standard interleave, the 2×1 group divisor for every component in multi-Y interleave — each group consumes exactly one sample per spec — and tile alignment only ever adds bytes, so no valid file is rejected; the multi-Y sizing and its end-to-end fixture came out of Codex review). Allocation itself usestry_reserve_exact, the bounded path's pattern, so any residual pathological-but-consistent geometry errors instead of aborting.F10 — SPS bit-depth validation.
bit_depth_y()/bit_depth_c()computed8 + bit_depth_*_minus8as a plain u8 add, and the decoder's lenient parse path read the fields throughbounded_ue_u8truncation — minus8 above 8 wrapped, above 255 truncated. Both fields are now read as rawueand rejected above 8 on both parse paths, so bit depths are guaranteed within 8..=16 (completing #15's earlier work on this workstream: theexpectabort and dimension overflows were already fixed there).Tests: a 65535×65535
ispeover a 6-byte rgb3 payload is rejected as malformed instead of aborting; bit-level SPS patching rejects minus8 of 9, 300, and maximal-ue while 8 (16-bit) still parses. Full suite green (136 lib tests), clippy-D warningsclean under the CI-pinned Rust 1.90.0.Source fork PR: laurens-pilot#7
@laurenspriem