Repository navigation
Fix RAR5 async decompression corruption when executable filters span the 4MB write boundary - #1395
Closed
adamhathcock with Copilot wants to merge 2 commits into
Closed
adamhathcock with Copilot wants to merge 2 commits into
adamhathcock with Copilot wants to merge 2 commits into
Conversation
Three bugs in the async version of UnpWriteBuf (used only in the async
decompression path) were causing data corruption when decompressing RAR5
archives containing executable filters (E8/E8E9/ARM) whose blocks spanned
the 4MB write boundary (UNPACK_MAX_WRITE):
1. WrittenFileSize was only incremented inside `if (OutMem != null)`, but
should always be incremented after ApplyFilter (matching sync behavior).
2. UnpSomeRead = true was missing from the filter processing path.
3. In the NotAllFiltersProcessed else branch (filter intersects write border):
- WrPtr was not updated to WrittenBorder, corrupting the window pointer
used to compute WriteBorder on the next flush cycle
- Remaining filters had NextWindow set to true (inverted logic), when
sync correctly sets them to false so they are processed next time
All three changes align the async path with the sync UnpWriteBuf logic.
Copilot
AI
changed the title
[WIP] Fix RAR5 decompression corruption during entry extraction
Fix RAR5 async decompression corruption when executable filters span the 4MB write boundary
Aug 1, 2026
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.
RAR5 decompression via the async reader path (
ReaderFactory.OpenAsyncReader) produced corrupted output starting at ~4 MB into certain entries. The sync path was unaffected. Root cause: three divergences betweenUnpWriteBufAsyncand the reference syncUnpWriteBufthat only manifest when an executable filter block (E8/E8E9/ARM) straddles theUNPACK_MAX_WRITE = 4 MBflush boundary.Bugs fixed in
UnpWriteBufAsyncWrittenFileSizetracked incorrectly — increment was insideif (OutMem != null), so it was skipped whenApplyFilterreturned null (unknown filter type). The sync version always increments it. This corrupts the file-offset argument passed to subsequent E8/E8E9 filter invocations.WrPtr = WrittenBordermissing (most critical) — when a filter block can't be fully written in the current pass (BlockLength > WriteSizeLeft), the sync version savesWrPtr = WrittenBorderto checkpoint the safe-to-output position. The async version omitted this entirely. SinceUnpWriteBuf*re-initialises its localWrittenBorderfromWrPtr, the next flush cycle started writing from the wrong window offset, producing the corrupted bytes visible in the hex dump.NextWindowset to inverted value — in the same "filter intersects boundary" branch, the sync version resets all remaining filters toNextWindow = false(process next time). The async version setNextWindow = trueunder different conditions, causing those filters to be incorrectly skipped on the next pass.