mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
[PR #1087] Fix async extraction of 7Zip archives with LZMA compression #1513
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Original Pull Request: https://github.com/adamhathcock/sharpcompress/pull/1087
State: closed
Merged: No
Async extraction of large 7z files fails with
DataErrorExceptioninLzmaStream.ReadAsync. The LZMA decoder has state corruption bugs in its async implementation (inLzmaStream.ReadAsync,Decoder.CodeAsync, andOutWindowoperations).Changes
SyncOnlyStreamwrapper inSevenZipArchive.cs: Forces async operations to use synchronous equivalents, bypassing buggy LZMA async code paths while maintaining async API surfaceSevenZipReader.GetEntryStream(): Wraps each entry's decompression stream inSyncOnlyStreamSevenZipReader.GetEntries(): Creates fresh streams per entry instead of sharing LZMA streams across multiple filesExample
The following code now works correctly for large 7z files:
Technical Notes
This is a workaround. The proper fix requires repairing the LZMA decoder's async state machine, which requires deep changes to the decoder implementation. The
SyncOnlyStreamwrapper ensures correctness at minimal performance cost for the 7Zip use case.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.