Skip to content

Fix DataErrorException when extracting LZMA-compressed zero-byte ZIP entries#1238

Merged
adamhathcock merged 3 commits intoreleasefrom
adam/fix-zip-extraction-error
Mar 1, 2026
Merged

Fix DataErrorException when extracting LZMA-compressed zero-byte ZIP entries#1238
adamhathcock merged 3 commits intoreleasefrom
adam/fix-zip-extraction-error

Conversation

@adamhathcock
Copy link
Owner

release version of #1237

fixes #1236

This pull request improves how the library handles ZIP archives containing LZMA-compressed entries with a known uncompressed size of zero. It ensures that such entries are correctly extracted as empty streams, both in regular and streaming scenarios. Additionally, it updates test coverage for these cases and adjusts some package dependencies.

LZMA zero-size entry handling:

  • Updated both synchronous (ZipFilePart.cs) and asynchronous (ZipFilePart.Async.cs) decompression logic to immediately return an empty stream and skip remaining compressed bytes when the uncompressed size is explicitly zero and the EOS marker flag is not set. This prevents unnecessary processing and fixes extraction for these edge cases. [1] [2]

Testing improvements:

  • Added a new test (Zip_LZMA_ZeroSizeEntry_CanExtract) to ensure that extracting a zero-size LZMA entry from a ZIP archive produces an empty output stream.
  • Added a streaming test (Zip_LZMA_ZeroSizeEntry_CanExtract_Streaming) to verify that zero-size LZMA entries are handled correctly during streaming extraction.

Dependency updates:

  • Downgraded Microsoft.NET.ILLink.Tasks package versions in packages.lock.json for both net10.0 and net8.0 target frameworks to ensure compatibility. [1] [2]

Copilot AI and others added 3 commits March 1, 2026 13:25
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>

# Conflicts:
#	src/SharpCompress/Common/Zip/ZipFilePart.Async.cs
#	src/SharpCompress/Common/Zip/ZipFilePart.cs
@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Mar 1, 2026

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 2
WARNING 0
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
src/SharpCompress/Common/Zip/ZipFilePart.cs 175 stream.Skip() reads ALL remaining bytes instead of just the LZMA compressed bytes, corrupting subsequent archive entries
src/SharpCompress/Common/Zip/ZipFilePart.Async.cs 245 stream.SkipAsync() reads ALL remaining bytes instead of just the LZMA compressed bytes, corrupting subsequent archive entries
Files Reviewed (6 files)
  • src/SharpCompress/Common/Zip/ZipFilePart.cs - 1 issue
  • src/SharpCompress/Common/Zip/ZipFilePart.Async.cs - 1 issue
  • src/SharpCompress/packages.lock.json - (package version changes, not reviewed)
  • tests/SharpCompress.Test/Zip/ZipArchiveTests.cs - OK
  • tests/SharpCompress.Test/Zip/ZipReaderTests.cs - OK
  • tests/TestArchives/Archives/Zip.lzma.empty.zip - (binary test file)

Note: The tests added (Zip_LZMA_ZeroSizeEntry_CanExtract and Zip_LZMA_ZeroSizeEntry_CanExtract_Streaming) only test a single-entry archive, so they won't catch the bug where reading past the entry corrupts subsequent entries.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes extraction of ZIP archives containing LZMA-compressed entries whose uncompressed size is explicitly zero (preventing DataErrorException), and adds regression tests for both seekable-archive and streaming-reader scenarios.

Changes:

  • Short-circuit LZMA decompression for known-zero uncompressed size entries (sync + async) and drain remaining compressed bytes.
  • Add new regression tests and a minimal test archive containing an empty LZMA entry.
  • Update packages.lock.json dependency resolutions for Microsoft.NET.ILLink.Tasks.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/SharpCompress/Common/Zip/ZipFilePart.cs Adds LZMA early-return path for zero-size entries.
src/SharpCompress/Common/Zip/ZipFilePart.Async.cs Adds async equivalent early-return path for zero-size entries.
tests/TestArchives/Archives/Zip.lzma.empty.zip Adds a fixture ZIP containing an empty LZMA-compressed entry.
tests/SharpCompress.Test/Zip/ZipArchiveTests.cs Adds seekable-archive regression test for extracting empty LZMA entry.
tests/SharpCompress.Test/Zip/ZipReaderTests.cs Adds streaming-reader regression test for extracting empty LZMA entry.
src/SharpCompress/packages.lock.json Adjusts locked versions for Microsoft.NET.ILLink.Tasks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants