Skip to content

Fix inflate match output bound check - #204

Open
HDauven wants to merge 1 commit into
Frommi:masterfrom
HDauven:fix-match-output-bound-check
Open

Fix inflate match output bound check#204
HDauven wants to merge 1 commit into
Frommi:masterfrom
HDauven:fix-match-output-bound-check

Conversation

@HDauven

@HDauven HDauven commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #200.

Since decompress_with_limit was added, this check has compared an absolute end position with the remaining output capacity. This can send matches through WriteLenBytesToEnd even when the whole match fits.

Compare the match length directly with the remaining capacity. The separate overlap check can also go because apply_match already handles the same case through transfer.

The overall performance difference is small since this sits outside the main inflate loop, but the check is now correct and avoids unnecessary state-machine work.

@HDauven
HDauven force-pushed the fix-match-output-bound-check branch from 4929027 to 9abcc07 Compare August 22, 2026 02:20
@HDauven
HDauven marked this pull request as ready for review August 22, 2026 02:37
@oyvindln

Copy link
Copy Markdown
Collaborator

This is probably the correct direction but will have to look over the full issue to see whether there is something else missing here.

Also something to look at performance-wise is how changing those checks affects the ability for the compiler do optimize out bounds checks later in that "switch case". Since we don't use unsafe, helping the compiler evade bounds checks and thus reducing branches and emitting code for panics in hot paths is important.

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.

HuffDecodeOuterLoop2: bytes_left()/get_ref().len() bounds-comparison regression since 0.9.0 (#183) forces the slow copy path

2 participants