Repository navigation
Fix RAR5 async decompression corruption in UnpWriteBufAsync - #1396
Merged
Merged
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.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a RAR5 async decompression corruption bug by bringing UnpWriteBufAsync’s filter/write-boundary logic back in sync with the reference synchronous implementation, addressing the ~4MB boundary corruption described in #1394. Also includes small diagnostics and tooling updates.
Changes:
- Align
UnpWriteBufAsyncfilter handling with sync behavior (write pointer checkpointing,NextWindowreset,UnpSomeRead, andWrittenFileSizeaccounting) to prevent corruption when executable filters span the 4MB write boundary. - Improve CRC mismatch diagnostics by including the entry key (file name) in the CRC mismatch exception message (with one async overload still needing alignment—see review comment).
- Bump .NET SDK patch and related lockfile dependencies for ILLink/ILCompiler.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/SharpCompress.AotSmoke/packages.lock.json | Updates ILCompiler/ILLink task versions for AOT smoke test lockfile. |
| src/SharpCompress/packages.lock.json | Updates ILLink task versions in the main library lockfile. |
| src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_async.cs | Fixes async unpack write/filter boundary logic to match sync UnpWriteBuf and prevent RAR5 output corruption. |
| src/SharpCompress/Compressors/Rar/RarCrcStream.cs | Refactors fields and improves sync CRC mismatch exception message with entry key. |
| src/SharpCompress/Compressors/Rar/RarCrcStream.Async.cs | Refactors async CRC tracking; partially updates CRC mismatch exception message (one overload remains inconsistent). |
| global.json | Bumps pinned .NET SDK patch version (rollForward remains disabled). |
Suppressed comments (1)
src/SharpCompress/Compressors/Rar/RarCrcStream.Async.cs:43
- In the byte[] ReadAsync overload, the CRC mismatch exception message is still "file crc mismatch" while the sync path and the Memory async overload now include the entry key (file name). This makes diagnostics inconsistent depending on which overload is used (and which target framework picks which overload).
else if (
!_disableCrc
&& GetCrc() != BitConverter.ToUInt32(_readStream.NotNull().CurrentCrc.NotNull(), 0)
&& count != 0
)
{
// NOTE: we use the last FileHeader in a multipart volume to check CRC
throw new InvalidFormatException("file crc mismatch");
}
This was referenced Aug 1, 2026
Closed
This was referenced Oct 26, 2026
This was referenced Nov 5, 2026
This was referenced Nov 12, 2026
This was referenced Nov 20, 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.
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):
WrittenFileSize was only incremented inside
if (OutMem != null), but should always be incremented after ApplyFilter (matching sync behavior).UnpSomeRead = true was missing from the filter processing path.
In the NotAllFiltersProcessed else branch (filter intersects write border):
All three changes align the async path with the sync UnpWriteBuf logic.
Fixes: #1394
Supersedes: #1395