Skip to content

Fix SeekableSharpCompressStream.StopRecording() to rewind to recorded… - #1393

Merged
adamhathcock merged 2 commits into
releasefrom
adam/flat-gzip-fix-stream-rewind
Jul 31, 2026
Merged

Fix SeekableSharpCompressStream.StopRecording() to rewind to recorded…#1393
adamhathcock merged 2 commits into
releasefrom
adam/flat-gzip-fix-stream-rewind

Conversation

@adamhathcock

Copy link
Copy Markdown
Owner

… 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

… 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
Copilot AI review requested due to automatic review settings July 31, 2026 13:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@adamhathcock
adamhathcock changed the base branch from master to release July 31, 2026 13:47
@adamhathcock
adamhathcock merged commit 246d968 into release Jul 31, 2026
3 checks passed
@adamhathcock
adamhathcock deleted the adam/flat-gzip-fix-stream-rewind branch July 31, 2026 15:31
This was referenced Jul 31, 2026
This was referenced Aug 3, 2026
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.

Flat GZip via ReaderFactory broken: stream seems not to be rewound after tar probe in GZipFactory.TryOpenReader

2 participants