Remove compressed tar archive#1360
Merged
Merged
Conversation
…s should be done with TarReader only
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens SharpCompress’s TAR API boundaries by enforcing that compressed tar wrappers (e.g., .tar.gz, .tar.bz2, .tar.xz, .tar.Z) are reader-only (TarReader / ReaderFactory) and can no longer be opened via the archive/random-access APIs (TarArchive / ArchiveFactory), with corresponding documentation updates.
Changes:
TarArchiveopen paths now validate inputs as raw tar only and reject compressed wrappers.TarFactoryarchive detection is simplified to raw-tar probing; reader paths addTryOpenReaderhelpers.- Tests and docs updated to assert/describe the new “compressed tar = reader-only” contract.
Review findings (blocking):
src/SharpCompress/Factories/TarFactory.cs: the method ending at line ~367 now throwsInvalidFormatException("Not a tar file.")where it previously fell back to opening a plain tar reader:- This strongly suggests raw tar may no longer be openable via the async reader factory path when no wrapper matches (regression vs the removed fallback).
- Proposed fix (restore the previous fallback behavior in that code path): reintroduce the two removed lines:
sharpCompressStream.Rewind();return (IAsyncReader)TarReader.OpenReader(sharpCompressStream, options);
src/SharpCompress/Archives/Tar/TarArchive.Factory.cs:EnsureRawTarFile/EnsureRawTarFileAsyncunconditionally callstream.Seek(0, ...). If a caller passes a non-seekable stream, this will likely throwNotSupportedExceptioninstead of the documented/expected argument validation behavior forTarArchive.OpenArchive(Stream)(seekable requirement). Consider an explicitif (!stream.CanSeek) throw new ArgumentException(...);before seeking.src/SharpCompress/Factories/TarFactory.cs:IsArchive(...)/IsArchiveAsync(...)now directly callTarArchive.IsTarFile(...)on the provided stream. IfIsTarFileadvances the stream (typical for header probing), this can create observable side-effects for callers expecting stream position to be preserved. Consider saving/restoring position whenCanSeek, or ensuring the caller always wraps with a rewindableSharpCompressStream.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/SharpCompress.Test/Tar/TarArchiveTests.cs | Adds explicit rejection tests for compressed tar wrappers via ArchiveFactory and TarArchive. |
| tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs | Adds async rejection tests for compressed tar wrappers. |
| tests/SharpCompress.Test/CompressionProviderTests.cs | Updates provider tests to validate decompression via TarReader rather than TarArchive. |
| tests/SharpCompress.Test/ArchiveFactoryTests.cs | Removes compressed-tar from “archive” test cases and adds explicit “not an archive” assertions for compressed tar. |
| src/SharpCompress/Factories/TarFactory.cs | Simplifies raw tar archive detection; introduces TryOpenReader helpers; adjusts async reader open behavior (potential regression). |
| src/SharpCompress/Archives/Tar/TarArchive.Factory.cs | Enforces raw-tar validation for TarArchive open methods via EnsureRawTarFile*. |
| src/SharpCompress/Archives/Tar/TarArchive.cs | Removes wrapper decompression support from TarArchive entry loading paths. |
| src/SharpCompress/Archives/Tar/TarArchive.Async.cs | Mirrors sync changes: no wrapper decompression and always seekable-mode parsing. |
| docs/TAR_SPEC.md | Documents “compressed tar wrappers are reader-only” and updates detection notes accordingly. |
| docs/FORMATS.md | Updates format support matrix to mark compressed tar wrappers as reader-only (no archive API). |
| docs/API.md | Clarifies that compressed tar wrappers are reader-only and not returned by GetArchiveInformation. |
| .agents/skills/tar-format/references/tar-format.md | Updates tar wrapper table and archive vs reader guidance to match the new behavior. |
This was referenced Jul 13, 2026
Merged
This was referenced Jul 14, 2026
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.
This pull request refines and clarifies the handling of compressed tar files in both the implementation and documentation. The main change is that compressed tar wrappers (like
.tar.gz,.tar.bz2, etc.) are now supported only through theTarReaderAPI, notTarArchiveorArchiveFactory. Attempts to open compressed tar files as archives will now be blocked and validated as errors. Documentation and code have been updated to reflect this behavior and to make the distinction between archive and reader APIs much clearer.API and Implementation changes:
TarArchive.OpenArchiveand related methods now validate that input streams are raw tar files, not compressed tar wrappers, and throw an error otherwise (src/SharpCompress/Archives/Tar/TarArchive.Factory.cs). [1] [2]src/SharpCompress/Archives/Tar/TarArchive.Factory.cs,src/SharpCompress/Archives/Tar/TarArchive.Async.cs). [1] [2] [3] [4] [5] [6]TarReader) remain the way to access compressed tar files, and related detection logic is clarified. [1] [2]Documentation updates:
docs/TAR_SPEC.md,docs/FORMATS.md,.agents/skills/tar-format/references/tar-format.md,docs/API.md) have been updated to clearly state that compressed tar wrappers are reader-only and cannot be opened as archives. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]Code cleanup:
TarArchive.cs.These changes ensure that the distinction between archive and reader APIs is enforced in both the code and documentation, preventing incorrect usage and making the supported scenarios explicit.