Skip to content

Conversation

@iremyux
Copy link
Contributor

@iremyux iremyux commented Sep 23, 2025

This PR improves error messages when users attempt to read compressed TAR archives. When TAR header parsing fails due to an invalid checksum field, the code now checks if the file might be a compressed archive (GZIP, BZIP2, XZ, ZIP, ZLIB, 7-Zip, or Zstandard) by examining compression magic numbers. If a compression format is detected, it throws a clear, localized error message indicating the specific compression format detected (e.g., "The file appears to be a GZIP archive. TAR format expected.").

Fixes #89056

Copilot AI review requested due to automatic review settings September 23, 2025 14:41
Copy link
Contributor

Copilot AI left a 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

@iremyux iremyux requested a review from Copilot October 27, 2025 11:47
Copy link
Contributor

Copilot AI left a 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.

Copy link
Contributor

Copilot AI left a 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.

Copy link
Contributor

Copilot AI left a 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.

@iremyux iremyux requested a review from Copilot November 10, 2025 15:45
Copy link
Contributor

Copilot AI left a 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 ThrowIfCompressedArchive method 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 expected InvalidDataException with the correct format name.
// Licensed to the .NET Foundation under one or more agreements.

iremyux and others added 2 commits November 11, 2025 09:45
@iremyux iremyux marked this pull request as ready for review November 13, 2025 14:07
@iremyux iremyux requested review from a team and Copilot November 13, 2025 14:07
Copy link
Contributor

Copilot AI left a 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.

…der.Read.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a 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 no new comments.

Copy link
Member

@rzikm rzikm left a comment

Choose a reason for hiding this comment

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

LGTM

@iremyux iremyux merged commit fa6bf38 into dotnet:main Nov 24, 2025
86 checks passed
@iremyux iremyux deleted the 89056-tar-magic-numbers branch November 26, 2025 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Formats.Tar linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tar: Detect magic numbers in archives compressed with popular algorithms

2 participants