-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add compression magic number detection to System.Formats.Tar with helpful error messages #119996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the System.Formats.Tar library by adding compression format detection at the beginning of tar archive reading. When users attempt to read a compressed tar file directly without decompression, the library now provides helpful error messages that identify the compression type and guide users on the appropriate solution.
- Adds magic number detection for common compression formats (GZIP, ZLIB, BZIP2, LZ4, XZ, etc.)
- Provides differentiated error messages for supported vs unsupported compression formats
- Integrates compression checking into both synchronous and asynchronous tar reading workflows
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| TarHeader.Read.cs | Adds compression detection logic and calls to check magic numbers during tar header reading |
| Strings.resx | Adds localized error message templates for supported and unsupported compression detection |
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs
Outdated
Show resolved
Hide resolved
…n supported/unsuported formats
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
…n supported/unsuported formats
…dotnet-runtime into 89056-tar-magic-numbers
…dotnet-runtime into 89056-tar-magic-numbers
…atch the magic numbers, if we cannot throw the parsing error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs:1
- The new
ThrowIfCompressedArchivemethod lacks test coverage. Consider adding tests for each supported compression format (GZIP, BZIP2, XZ, Zstandard, ZIP, 7-Zip, ZLIB) to verify the detection logic and error messages work correctly. Tests should verify that each compression format's magic number is properly detected and throws the expectedInvalidDataExceptionwith the correct format name.
// Licensed to the .NET Foundation under one or more agreements.
| /// <exception cref="InvalidDataException">Thrown if a compression format is detected</exception> | ||
| /// </summary> |
Copilot
AI
Nov 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XML doc comment for the exception should use proper XML documentation tags. The <exception> tag should be placed outside the closing </summary> tag and include a proper description with a period at the end.
| /// <exception cref="InvalidDataException">Thrown if a compression format is detected</exception> | |
| /// </summary> | |
| /// </summary> | |
| /// <exception cref="InvalidDataException">Thrown if a compression format is detected.</exception> |
This PR improves the experience of reading compressed tar archives by detecting common compression formats before parsing. It now provides clear, localized messages that explain whether the archive is compressed with a supported format (e.g., GZIP, ZLIB) or an unsupported one (e.g., BZIP2, LZ4, XZ). For supported formats, it guides users to wrap the stream with the right .NET class, and for unsupported formats, it advises decompression first.
Fixes #89056