fix: copyBytes source index wrapping in decode_reader#61
Open
hobeone wants to merge 1 commit into
Open
Conversation
copyBytes is the LZ sliding-window copy primitive used by all RAR decompression versions (v2.0, v2.9, v5.0, v7.0). When the source index reaches the end of the circular window buffer, it must wrap to 0 — this is standard LZ77 circular-buffer behavior, not corruption. The fast-path bulk-copy branch (i > d.w) already handled this wrap correctly by splitting the copy into two segments. However, the byte-by-byte fallback loop (used when source and destination overlap, e.g. RLE-like patterns) was missing the wrap, causing a panic with index-out-of-range on crafted RAR3 archives.
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.
Full disclosure, this was found with an LLM analysis. Seems to be a real issue though - I didn't see a policy on accepting LLM changes or not so creating a pull request.
^^^ human -- LLM vvv
copyBytes is the LZ sliding-window copy primitive used by all RAR decompression versions (v2.0, v2.9, v5.0, v7.0). When the source index reaches the end of the circular window buffer, it must wrap to 0 — this is standard LZ77 circular-buffer behavior, not corruption.
The fast-path bulk-copy branch (i > d.w) already handled this wrap correctly by splitting the copy into two segments. However, the byte-by-byte fallback loop (used when source and destination overlap, e.g. RLE-like patterns) was missing the wrap, causing a panic with index-out-of-range on crafted RAR3 archives.