Skip to content

Size unci generic-compression output exactly and fail allocations cleanly - #24

Merged
laurenspriem merged 1 commit into
ente:mainfrom
laurens-pilot:fix/unci-budget-followups
Nov 2, 2026
Merged

laurenspriem merged 1 commit into
ente:mainfrom
laurens-pilot:fix/unci-budget-followups

Conversation

@laurens-pilot

Copy link
Copy Markdown

Follow-up to the review of #19.

Generic-compressed unci items now get an output budget that matches exactly what the reader consumes in every interleave mode. pixel_size layouts with sub-byte groups now decode compressed, and any decompressed bytes beyond the layout are rejected. Layouts whose padding (pixel_size, row or tile alignment, padded components) exceeds 8× their real sample data and 16 MiB are rejected before anything is decompressed, as are large-window brotli streams. Before this, a 232-byte file could make the brotli decoder request 1 GiB. Allocation failures on the unci decode path now report ResourceLimit instead of aborting the process, including when the decompressed output buffer has to grow.

Behaviour changes:

  • Mixed-interleave row padding: compressed mixed-interleave payloads padded for row_align_size are rejected, because the reader ignores that field. Plain copies still decode.
  • New public error variants: DecodeUncompressedError::ResourceLimit, TransformGuardError::AllocationFailed and ExtractUncompressedItemDataError::PayloadAllocationFailed. None of these enums is non_exhaustive, so exhaustive downstream matches need updating.
  • Fallible transform allocations: rotate, mirror and crop now allocate fallibly on every decode path, including HEIC.

Known limits:

  • Remaining aborts: fixed codec state (flate2 buffers and decoder state, standard-window brotli state), allocations proportional to the input size, and error strings can still abort on allocation failure.
  • Not tested: 32-bit builds.

This overlaps with #13, which changes pixel_size into an exact stride. Whichever PR lands second must drop the one-byte residual in uncompressed_pixel_group_tile_size_bytes, and the new differential sweep test will fail until it does.

Source fork PR: laurens-pilot#14

@laurenspriem

…anly

Follow-ups to the review of ente#19.

- size the compressed output budget from what the reader consumes in
  every interleave mode, so pixel_size layouts with sub-byte groups
  decode compressed and excess output is rejected
- reject layouts whose padding exceeds 8x their non-padded sample data
  and 16 MiB before decompressing, and reject large-window brotli
  streams before the decoder can request a ring buffer of up to 1 GiB
- report ResourceLimit instead of aborting when the unci payload,
  channel, RGBA, tile scratch, conversion or transform allocations
  fail, and when the decompressed output buffer cannot grow
- check multi-y component roles and sampling before the budget, so
  unsupported layouts keep reporting UnsupportedFeature
- compare the budget with the reader across generated layouts
@laurens-pilot

Copy link
Copy Markdown
Author

@codex review

@laurenspriem
laurenspriem merged commit a1b0198 into ente:main Nov 2, 2026
3 checks passed
@laurens-pilot
laurens-pilot deleted the fix/unci-budget-followups branch November 2, 2026 10:03
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