Release to master#1267
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Fix ZIP64 stream bounding and WinZip AES read-state corruption in ZIP reader
…case first block Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
…size-zstandard
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com> Agent-Logs-Url: https://github.com/adamhathcock/sharpcompress/sessions/3037a2f7-f243-4261-802f-e8c83b4d6722
…, NullRef) Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com> Agent-Logs-Url: https://github.com/adamhathcock/sharpcompress/sessions/3037a2f7-f243-4261-802f-e8c83b4d6722
… helper Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com> Agent-Logs-Url: https://github.com/adamhathcock/sharpcompress/sessions/3037a2f7-f243-4261-802f-e8c83b4d6722
…pressor-crash Fix denial-of-service crashes in 8 decompressors on malformed input
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (19 files)
OverviewThe PR adds comprehensive error handling improvements across multiple decompression formats (BZip2, ArcLZW, LZW, Deflate64, PPMd, LZMA, Reduce, Squeezed, Explode). It also refactors the Winzip AES crypto stream logic for better correctness and increases the default rewindable buffer size to handle large ZStandard blocks. Key Improvements
Notes
|
There was a problem hiding this comment.
Pull request overview
This PR hardens SharpCompress decompression against malformed/corrupt inputs (notably BZip2 and ARC/LZW), refactors WinZip AES CTR handling for correctness across partial reads, and adjusts buffering defaults to improve format detection for large Zstandard blocks.
Changes:
- Added defensive bounds/validity checks across multiple decompressor implementations to ensure malformed inputs raise library exceptions instead of raw runtime exceptions.
- Refactored WinZip AES crypto stream to track a rolling keystream offset for correct behavior across non-aligned sync/async reads.
- Increased default rewindable buffer size and added/expanded regression tests (malformed input, Zip64 stream bounding, Zstd+AES archives).
Reviewed changes
Copilot reviewed 25 out of 26 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/SharpCompress.Test/Zip/ZipFilePartTests.cs | Adds coverage to ensure ZIP entry streams are bounded when compressed size is known (incl. Zip64 markers). |
| tests/SharpCompress.Test/Zip/ZipArchiveTests.cs | Adds tests for Zstd+WinZip AES archives and a large Zip64 regression test (currently problematic). |
| tests/SharpCompress.Test/Streams/WinzipAesCryptoStreamTests.cs | Adds keystream/CTR regression tests for aligned and non-aligned sync/async reads. |
| tests/SharpCompress.Test/MalformedInputTests.cs | Adds “malformed input should throw SharpCompressException” regression tests across multiple formats. |
| src/SharpCompress/Readers/ReaderOptions.cs | Updates docs to reflect new default rewindable buffer sizing rationale for Zstandard. |
| src/SharpCompress/Compressors/Squeezed/SqueezedStream.cs | Adds Huffman tree index validation to avoid out-of-range access on corrupt inputs. |
| src/SharpCompress/Compressors/Squeezed/SqueezedStream.Async.cs | Async parity for Huffman tree index validation. |
| src/SharpCompress/Compressors/Reduce/ReduceStream.cs | Adds bounds check for reduce “next byte table” lookup indices. |
| src/SharpCompress/Compressors/Reduce/ReduceStream.Async.cs | Async parity for reduce table index bounds check. |
| src/SharpCompress/Compressors/PPMd/I1/Model.cs | Adds initialization validation to prevent use of uninitialized model context. |
| src/SharpCompress/Compressors/Lzw/LzwStream.cs | Adds header validation (min bits) and ensures header parse failures mark EOF state. |
| src/SharpCompress/Compressors/Lzw/LzwStream.Async.cs | Async parity for LZW header validation and failure handling. |
| src/SharpCompress/Compressors/LZMA/LZ/LzOutWindow.cs | Validates dictionary/window size to prevent invalid allocations/usage. |
| src/SharpCompress/Compressors/Explode/ExplodeStream.cs | Validates Huffman table setup result and throws a format exception on failure. |
| src/SharpCompress/Compressors/Explode/ExplodeStream.Async.cs | Async parity for explode table setup validation. |
| src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs | Adds bounds checking during Huffman table construction to prevent invalid indexing. |
| src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs | Adds extensive BZip2 validation (stream init, selectors, Huffman decode bounds, block bounds). |
| src/SharpCompress/Compressors/BZip2/CBZip2InputStream.Async.cs | Async parity for BZip2 validation and stream init handling. |
| src/SharpCompress/Compressors/ArcLzw/ArcLzwStream.cs | Adds empty-input and code-range validation for ARC LZW decompression. |
| src/SharpCompress/Common/Zip/ZipFilePart.cs | Adjusts crypto stream bounding rules to avoid unbounded reads when compressed size is known. |
| src/SharpCompress/Common/Zip/ZipFilePart.Async.cs | Async parity for ZIP crypto stream bounding logic. |
| src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs | Refactors CTR keystream handling to use _counterOutOffset across partial reads. |
| src/SharpCompress/Common/Zip/WinzipAesCryptoStream.Async.cs | Async parity for CTR keystream offset handling. |
| src/SharpCompress/Common/Constants.cs | Increases default rewindable buffer size and updates documentation accordingly. |
| Directory.Build.props | Suppresses IDE0051 warnings repository-wide. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| VerifyMixedZstandardArchive(archive); | ||
| } | ||
|
|
||
| [Fact(Explicit = true)] |
There was a problem hiding this comment.
[Fact(Explicit = true)] is not a supported parameter on xUnit's FactAttribute (xUnit typically uses Skip = "..." to disable tests). If this isn't recognized by the runner, this test will run by default and will attempt to generate/write a ~4GB ZIP on disk, which is not suitable for CI. Consider converting this to [Fact(Skip = "...")] (or an existing conditional/trait-based skip mechanism used in this repo) and keep the large-file generation behind an explicit opt-in.
| [Fact(Explicit = true)] | |
| [Fact(Skip = "Generates a very large Zip64 archive; run manually when explicitly needed.")] |
Updated [SharpCompress](https://github.com/adamhathcock/sharpcompress) from 0.48.1 to 0.49.0. <details> <summary>Release notes</summary> _Sourced from [SharpCompress's releases](https://github.com/adamhathcock/sharpcompress/releases)._ ## 0.49.0 This should contain a lot of write async fixes and some breaking API changes that fix previous broke `net48` usage ## What's Changed * Rename IWriteableArchiveFactory.cs to IWritableArchiveFactory.cs by @Copilot in adamhathcock/sharpcompress#1244 * Some API clean up from GPT 5.4 by @adamhathcock in adamhathcock/sharpcompress#1243 * Release to master by @adamhathcock in adamhathcock/sharpcompress#1267 * Fix three BLAKE2sp correctness bugs and eliminate allocations in hot path by @coderb in adamhathcock/sharpcompress#1266 * Corrected async examples. by @dlemstra in adamhathcock/sharpcompress#1277 * Fix setting invalid access time fails extraction by @aromaa in adamhathcock/sharpcompress#1279 * Fix incorrect code examples in docs for sync/async usage by @Copilot in adamhathcock/sharpcompress#1280 * Replace APPNOTE.TXT contents with reference link note by @puk06 in adamhathcock/sharpcompress#1286 * Release to Master by @adamhathcock in adamhathcock/sharpcompress#1274 * update docs for tar gap analysis and XZ usage by @adamhathcock in adamhathcock/sharpcompress#1288 * Add a PooledMemoryStream to avoid allocating by @adamhathcock in adamhathcock/sharpcompress#1275 * fix: Change LeaveStreamOpen default from true to false by @puk06 in adamhathcock/sharpcompress#1293 * Fix usage of ReaderOptions and pre-defined values by @adamhathcock in adamhathcock/sharpcompress#1295 * Enforce seekable, readable and writable on streams by @adamhathcock in adamhathcock/sharpcompress#1297 * Add ArchiveInformation record for consolidated archive detection and capability inspection by @Copilot in adamhathcock/sharpcompress#1299 * merge release to master by @adamhathcock in adamhathcock/sharpcompress#1314 * Some clean up and test clean up by @adamhathcock in adamhathcock/sharpcompress#1321 * Finish Write Async by @adamhathcock in adamhathcock/sharpcompress#1323 * More complete Tar implementation: USTAR, PAX, etc. by @adamhathcock in adamhathcock/sharpcompress#1289 * Add Polysharp and adjustments that do not break legacy frameworks by @adamhathcock in adamhathcock/sharpcompress#1330 * Fix null `IVolume.FileName` for single-volume file-based archives by @Copilot in adamhathcock/sharpcompress#1333 * Add skills by @adamhathcock in adamhathcock/sharpcompress#1332 * add AOT smoke and missing tests by @adamhathcock in adamhathcock/sharpcompress#1334 ## New Contributors * @dlemstra made their first contribution in adamhathcock/sharpcompress#1277 * @aromaa made their first contribution in adamhathcock/sharpcompress#1279 * @puk06 made their first contribution in adamhathcock/sharpcompress#1286 **Full Changelog**: adamhathcock/sharpcompress@0.48.1...0.49.0 ## 0.49.0-beta.140 ## What's Changed * Add Polysharp and adjustments that do not break legacy frameworks by @adamhathcock in adamhathcock/sharpcompress#1330 **Full Changelog**: adamhathcock/sharpcompress@0.49.0-beta.136...0.49.0-beta.140 ## 0.49.0-beta.136 ## What's Changed * Rename IWriteableArchiveFactory.cs to IWritableArchiveFactory.cs by @Copilot in adamhathcock/sharpcompress#1244 * Some API clean up from GPT 5.4 by @adamhathcock in adamhathcock/sharpcompress#1243 * Release to master by @adamhathcock in adamhathcock/sharpcompress#1267 * Fix three BLAKE2sp correctness bugs and eliminate allocations in hot path by @coderb in adamhathcock/sharpcompress#1266 * Corrected async examples. by @dlemstra in adamhathcock/sharpcompress#1277 * Fix setting invalid access time fails extraction by @aromaa in adamhathcock/sharpcompress#1279 * Fix incorrect code examples in docs for sync/async usage by @Copilot in adamhathcock/sharpcompress#1280 * Replace APPNOTE.TXT contents with reference link note by @puk06 in adamhathcock/sharpcompress#1286 * Release to Master by @adamhathcock in adamhathcock/sharpcompress#1274 * update docs for tar gap analysis and XZ usage by @adamhathcock in adamhathcock/sharpcompress#1288 * Add a PooledMemoryStream to avoid allocating by @adamhathcock in adamhathcock/sharpcompress#1275 * fix: Change LeaveStreamOpen default from true to false by @puk06 in adamhathcock/sharpcompress#1293 * Fix usage of ReaderOptions and pre-defined values by @adamhathcock in adamhathcock/sharpcompress#1295 * Enforce seekable, readable and writable on streams by @adamhathcock in adamhathcock/sharpcompress#1297 * Add ArchiveInformation record for consolidated archive detection and capability inspection by @Copilot in adamhathcock/sharpcompress#1299 * merge release to master by @adamhathcock in adamhathcock/sharpcompress#1314 * Some clean up and test clean up by @adamhathcock in adamhathcock/sharpcompress#1321 * Finish Write Async by @adamhathcock in adamhathcock/sharpcompress#1323 * More complete Tar implementation: USTAR, PAX, etc. by @adamhathcock in adamhathcock/sharpcompress#1289 ## New Contributors * @dlemstra made their first contribution in adamhathcock/sharpcompress#1277 * @aromaa made their first contribution in adamhathcock/sharpcompress#1279 * @puk06 made their first contribution in adamhathcock/sharpcompress#1286 **Full Changelog**: adamhathcock/sharpcompress@0.48.1...0.49.0-beta1 Commits viewable in [compare view](adamhathcock/sharpcompress@0.48.1...0.49.0). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Updated [SharpCompress](https://github.com/adamhathcock/sharpcompress) from 0.48.1 to 0.49.1. <details> <summary>Release notes</summary> _Sourced from [SharpCompress's releases](https://github.com/adamhathcock/sharpcompress/releases)._ ## 0.49.1 ## What's Changed * Close writable entry streams during async archive disposal by @Copilot in adamhathcock/sharpcompress#1338 * Restore `WriteToDirectoryAsync` progress callbacks for solid 7z archives by @Copilot in adamhathcock/sharpcompress#1340 * Try to fix global.json to avoid churn in locks by @adamhathcock in adamhathcock/sharpcompress#1341 * Fix tar archive enumeration after fully reading entry streams by @adamhathcock in adamhathcock/sharpcompress#1342 **Full Changelog**: adamhathcock/sharpcompress@0.49.0...0.49.1 ## 0.49.0 This should contain a lot of write async fixes and some breaking API changes that fix previous broke `net48` usage ## What's Changed * Rename IWriteableArchiveFactory.cs to IWritableArchiveFactory.cs by @Copilot in adamhathcock/sharpcompress#1244 * Some API clean up from GPT 5.4 by @adamhathcock in adamhathcock/sharpcompress#1243 * Release to master by @adamhathcock in adamhathcock/sharpcompress#1267 * Fix three BLAKE2sp correctness bugs and eliminate allocations in hot path by @coderb in adamhathcock/sharpcompress#1266 * Corrected async examples. by @dlemstra in adamhathcock/sharpcompress#1277 * Fix setting invalid access time fails extraction by @aromaa in adamhathcock/sharpcompress#1279 * Fix incorrect code examples in docs for sync/async usage by @Copilot in adamhathcock/sharpcompress#1280 * Replace APPNOTE.TXT contents with reference link note by @puk06 in adamhathcock/sharpcompress#1286 * Release to Master by @adamhathcock in adamhathcock/sharpcompress#1274 * update docs for tar gap analysis and XZ usage by @adamhathcock in adamhathcock/sharpcompress#1288 * Add a PooledMemoryStream to avoid allocating by @adamhathcock in adamhathcock/sharpcompress#1275 * fix: Change LeaveStreamOpen default from true to false by @puk06 in adamhathcock/sharpcompress#1293 * Fix usage of ReaderOptions and pre-defined values by @adamhathcock in adamhathcock/sharpcompress#1295 * Enforce seekable, readable and writable on streams by @adamhathcock in adamhathcock/sharpcompress#1297 * Add ArchiveInformation record for consolidated archive detection and capability inspection by @Copilot in adamhathcock/sharpcompress#1299 * merge release to master by @adamhathcock in adamhathcock/sharpcompress#1314 * Some clean up and test clean up by @adamhathcock in adamhathcock/sharpcompress#1321 * Finish Write Async by @adamhathcock in adamhathcock/sharpcompress#1323 * More complete Tar implementation: USTAR, PAX, etc. by @adamhathcock in adamhathcock/sharpcompress#1289 * Add Polysharp and adjustments that do not break legacy frameworks by @adamhathcock in adamhathcock/sharpcompress#1330 * Fix null `IVolume.FileName` for single-volume file-based archives by @Copilot in adamhathcock/sharpcompress#1333 * Add skills by @adamhathcock in adamhathcock/sharpcompress#1332 * add AOT smoke and missing tests by @adamhathcock in adamhathcock/sharpcompress#1334 ## New Contributors * @dlemstra made their first contribution in adamhathcock/sharpcompress#1277 * @aromaa made their first contribution in adamhathcock/sharpcompress#1279 * @puk06 made their first contribution in adamhathcock/sharpcompress#1286 **Full Changelog**: adamhathcock/sharpcompress@0.48.1...0.49.0 ## 0.49.0-beta.140 ## What's Changed * Add Polysharp and adjustments that do not break legacy frameworks by @adamhathcock in adamhathcock/sharpcompress#1330 **Full Changelog**: adamhathcock/sharpcompress@0.49.0-beta.136...0.49.0-beta.140 ## 0.49.0-beta.136 ## What's Changed * Rename IWriteableArchiveFactory.cs to IWritableArchiveFactory.cs by @Copilot in adamhathcock/sharpcompress#1244 * Some API clean up from GPT 5.4 by @adamhathcock in adamhathcock/sharpcompress#1243 * Release to master by @adamhathcock in adamhathcock/sharpcompress#1267 * Fix three BLAKE2sp correctness bugs and eliminate allocations in hot path by @coderb in adamhathcock/sharpcompress#1266 * Corrected async examples. by @dlemstra in adamhathcock/sharpcompress#1277 * Fix setting invalid access time fails extraction by @aromaa in adamhathcock/sharpcompress#1279 * Fix incorrect code examples in docs for sync/async usage by @Copilot in adamhathcock/sharpcompress#1280 * Replace APPNOTE.TXT contents with reference link note by @puk06 in adamhathcock/sharpcompress#1286 * Release to Master by @adamhathcock in adamhathcock/sharpcompress#1274 * update docs for tar gap analysis and XZ usage by @adamhathcock in adamhathcock/sharpcompress#1288 * Add a PooledMemoryStream to avoid allocating by @adamhathcock in adamhathcock/sharpcompress#1275 * fix: Change LeaveStreamOpen default from true to false by @puk06 in adamhathcock/sharpcompress#1293 * Fix usage of ReaderOptions and pre-defined values by @adamhathcock in adamhathcock/sharpcompress#1295 * Enforce seekable, readable and writable on streams by @adamhathcock in adamhathcock/sharpcompress#1297 * Add ArchiveInformation record for consolidated archive detection and capability inspection by @Copilot in adamhathcock/sharpcompress#1299 * merge release to master by @adamhathcock in adamhathcock/sharpcompress#1314 * Some clean up and test clean up by @adamhathcock in adamhathcock/sharpcompress#1321 * Finish Write Async by @adamhathcock in adamhathcock/sharpcompress#1323 * More complete Tar implementation: USTAR, PAX, etc. by @adamhathcock in adamhathcock/sharpcompress#1289 ## New Contributors * @dlemstra made their first contribution in adamhathcock/sharpcompress#1277 * @aromaa made their first contribution in adamhathcock/sharpcompress#1279 * @puk06 made their first contribution in adamhathcock/sharpcompress#1286 **Full Changelog**: adamhathcock/sharpcompress@0.48.1...0.49.0-beta1 Commits viewable in [compare view](adamhathcock/sharpcompress@0.48.1...0.49.1). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This pull request introduces a number of improvements focused on increasing the robustness and correctness of archive decompression, particularly for BZip2 and ArcLzw formats, as well as refactoring the Winzip AES crypto stream logic for better correctness and maintainability. It also increases the default rewindable buffer size to better handle large ZStandard blocks and silences a specific IDE warning. The most important changes are summarized below:
Robustness and Error Handling Improvements
Winzip AES Crypto Stream Refactoring
_counterOutOffset) instead of a final block flag, improving correctness and simplifying the block transformation logic for both sync and async code paths. [1] [2] [3]Buffering and Performance
RewindableBufferSizefrom 81KB to 160KB to support ZStandard's worst-case block sizes, reducing the risk of failed format detection on large blocks. [1] [2]Code Quality and Maintenance
These changes collectively make the decompression codebase more robust, maintainable, and better suited for handling edge cases and corrupted input.