Skip to content

Harden unci channel allocation and SPS bit depths (HEIF Heist F7/F10) - #18

Merged
laurenspriem merged 2 commits into
ente:mainfrom
laurens-pilot:fix/heif-heist-f7-f10-hardening
Oct 30, 2026
Merged

laurenspriem merged 2 commits into
ente:mainfrom
laurens-pilot:fix/heif-heist-f7-f10-hardening

Conversation

@laurens-pilot

Copy link
Copy Markdown

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_internal allocated pixel_count u16 samples per channel straight from the ispe/uncC geometry, before the item payload was even extracted — a lying ispe on 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 uses try_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() computed 8 + bit_depth_*_minus8 as a plain u8 add, and the decoder's lenient parse path read the fields through bounded_ue_u8 truncation — minus8 above 8 wrapped, above 255 truncated. Both fields are now read as raw ue and rejected above 8 on both parse paths, so bit depths are guaranteed within 8..=16 (completing #15's earlier work on this workstream: the expect abort and dimension overflows were already fixed there).

Tests: a 65535×65535 ispe over 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 warnings clean under the CI-pinned Rust 1.90.0.

Source fork PR: laurens-pilot#7

@laurenspriem

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.
@laurens-pilot

Copy link
Copy Markdown
Author

@codex review

@laurenspriem
laurenspriem merged commit fbb8c7b into ente:main Oct 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants