Fix SeekableSharpCompressStream.StopRecording() to rewind to recorded… - #1393
Merged
Conversation
… position When SeekableSharpCompressStream.StopRecording() was called (e.g. after the tar probe in GZipFactory.TryOpenReader), it cleared _recordedPosition without seeking back to it. This left the underlying FileStream at the advanced position reached during the probe, so the subsequent GZipReader would start reading from the wrong offset, producing Key=null and 0 extracted bytes. Fix: seek back to _recordedPosition before clearing it, matching the behavior of the non-seekable SharpCompressStream.StopRecording() which rewinds _logicalPosition. Also enhance the existing GZip_ReaderFactory_FlatGZip test to actually verify the extracted content (not just MoveToNextEntry returns true), and add an async variant. Closes #1391
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes an incorrect stream position after format probing when using ReaderFactory on flat .gz files backed by a seekable stream. The change ensures SeekableSharpCompressStream.StopRecording() rewinds to the recorded anchor position before clearing it, preventing GZipReader from starting at an advanced offset (which previously could yield Key=null and 0 extracted bytes).
Changes:
- Fix
SeekableSharpCompressStream.StopRecording()to seek back to the recording anchor before clearing it. - Strengthen the existing flat-GZip ReaderFactory test to validate extracted payload bytes.
- Add an async counterpart test that validates the same behavior via
OpenAsyncReader/ async extraction.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/SharpCompress/IO/SeekableSharpCompressStream.cs | Rewinds to the recording anchor on StopRecording() to match non-seekable rewind-on-stop semantics and prevent incorrect downstream read offsets. |
| tests/SharpCompress.Test/GZip/GZipReaderTests.cs | Enhances the flat .gz ReaderFactory test to assert extracted content correctness (not just entry enumeration). |
| tests/SharpCompress.Test/GZip/GZipReaderAsyncTests.cs | Adds an async flat .gz ReaderFactory test validating async extraction produces the correct bytes. |
This was referenced Jul 31, 2026
Closed
This was referenced Aug 3, 2026
Merged
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.
… position
When SeekableSharpCompressStream.StopRecording() was called (e.g. after the tar probe in GZipFactory.TryOpenReader), it cleared _recordedPosition without seeking back to it. This left the underlying FileStream at the advanced position reached during the probe, so the subsequent GZipReader would start reading from the wrong offset, producing Key=null and 0 extracted bytes.
Fix: seek back to _recordedPosition before clearing it, matching the behavior of the non-seekable SharpCompressStream.StopRecording() which rewinds _logicalPosition.
Also enhance the existing GZip_ReaderFactory_FlatGZip test to actually verify the extracted content (not just MoveToNextEntry returns true), and add an async variant.
Closes #1391
Supersedes #1392