Skip to content

BroCatli: keep both header bytes when an empty stream straddles a byte boundary - #269

Open
lenamonj wants to merge 1 commit into
dropbox:masterfrom
lenamonj:concat-empty-stream-straddle
Open

lenamonj wants to merge 1 commit into
dropbox:masterfrom
lenamonj:concat-empty-stream-straddle

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 7, 2026

Copy link
Copy Markdown

Concatenating an empty stream between two others aborted with BrotliFileNotCraftedForAppend whenever the preceding stream's sanitized bit offset was 7, and catbrotli turned that into a panic with no output. Same class as #258, #260 and #266, reached from a different bit position.

A complete empty stream is all header, so its ISLAST/ISLASTEMPTY pair is its final metablock, and at offset 7 that pair straddles a byte boundary. shift_and_check_new_stream_header retracted exactly one byte to form the retained tail, leaving the pair's high bit in a byte already handed to the caller; the next flush_previous_stream saw a lone set bit and rejected the file. It now retains both bytes when the call wrote two. For every other header flush_previous_stream re-emits the second byte untouched, so output for streams that already worked is unchanged. A header split across two stream calls (output buffers under three bytes) is not covered here.

The new unit test builds the straddle without an encoder (window 15) and fails before the change with left: BrotliFileNotCraftedForAppend, right: NeedsMoreInput.

Tests: cargo fmt --check, cargo test (42 + 101), cargo test --doc, cargo test --features portable-float.

…e boundary

A complete empty stream is all header, so at a realignment offset of 7 its ISLAST/ISLASTEMPTY pair straddles a byte boundary. Retracting one byte for the retained tail left the pair's high bit in a byte already handed to the caller, and the next flush_previous_stream rejected the file with BrotliFileNotCraftedForAppend. Retain both bytes when the call wrote two; every other header re-emits the second byte untouched.
@CLAassistant

CLAassistant commented Sep 7, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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