Repository navigation
Fix ArgumentException in ZlibBaseStream when disposing mid-stream GZip probe in ReaderFactory - #1371
Conversation
|
@copilot why doesn't archive detection find this problem? It should |
|
@copilot look at this an ensure it solves the original issue |
Yes — the fix resolves the original issue. The regression test Root cause recap: Why archive detection didn't surface the same bug: The fix: Wrapping the probe decompressor in |
There was a problem hiding this comment.
Pull request overview
Fixes a regression where ReaderFactory.OpenReader() fails on flat (non-tar) .gz files due to the GZip “tar-in-gz” probe path interacting badly with disposal/finalization behavior.
Changes:
- Update
GZipFactory.TryOpenReaderto probe tar-in-gz via a non-disposing wrapper to avoid exceptions during probe-stream disposal. - Add a regression test ensuring flat gzip files can be opened via
ReaderFactory. - Bump pinned .NET SDK / locked package versions and remove an RTK hook configuration file.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/SharpCompress.Test/GZip/GZipReaderTests.cs | Adds regression coverage for opening a flat .gz via ReaderFactory. |
| src/SharpCompress/Factories/GZipFactory.cs | Adjusts tar-in-gz probe to avoid disposing the probe decompressor. |
| global.json | Updates the pinned .NET SDK version. |
| src/SharpCompress/packages.lock.json | Updates locked package versions (incl. ILLink tasks). |
| tests/SharpCompress.AotSmoke/packages.lock.json | Updates locked AOT-related package versions. |
| .github/hooks/rtk-rewrite.json | Removes RTK hook configuration. |
| // Do not dispose the probe GZip stream directly. Disposing after a partial probe read | ||
| // can throw in the decompressor finalize path, so probe through a non-disposing wrapper. | ||
| using var testStream = SharpCompressStream.CreateNonDisposing( | ||
| options.Providers.CreateDecompressStream( | ||
| CompressionType.GZip, | ||
| SharpCompressStream.CreateNonDisposing(sharpCompressStream), | ||
| CompressionContext.FromStream(sharpCompressStream).WithReaderOptions(options) | ||
| ) | ||
| ); |
ReaderFactory.OpenReaderthrowsArgumentException: Destination is too shorton any flat (non-tar) gzip file.GZipFactory.TryOpenReaderreads 512 decompressed bytes to detect tar-in-gz, then disposes the probe stream — triggeringZlibBaseStream.finish(), which unconditionally attempts trailer extraction even mid-stream, overflowing an 8-byte stack span when the inflater's input buffer holds far more than 8 bytes.Changes
ZlibBaseStream.finish()(sync + async): Guard trailer read/validation behind aZ_STREAM_ENDcheck so it is skipped when the inflater hasn't finished; bound the input-buffer copy toMath.Min(_z.AvailableBytesIn, 8)to prevent the span overflow even at genuine end-of-stream with trailing data (multi-member gzip, RFC 1952 §2.2). Applies to both the sync block (~line 336) and its async duplicate (~line 486).ReaderFactorytest toGZipReaderTestscovering the path that was previously untested and silently broken since 0.48.0.