Skip to content

Limit metadata block size when reading TAR archives#127602

Open
iremyux wants to merge 1 commit intodotnet:mainfrom
iremyux:tar-metadata-check
Open

Limit metadata block size when reading TAR archives#127602
iremyux wants to merge 1 commit intodotnet:mainfrom
iremyux:tar-metadata-check

Conversation

@iremyux
Copy link
Copy Markdown
Contributor

@iremyux iremyux commented Apr 30, 2026

Limits the maximum allowed size of PAX extended attribute blocks and GNU LongPath/LongLink data sections to 1 MB when reading TAR archives by introducing a MaxMetadataBlockSize constant (1 MB).

@iremyux iremyux requested a review from a team April 30, 2026 11:08
@iremyux iremyux self-assigned this Apr 30, 2026
Copilot AI review requested due to automatic review settings April 30, 2026 11:08
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-formats-tar
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
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 tightens TAR archive parsing by limiting the maximum size of metadata data sections (PAX extended attributes and GNU LongPath/LongLink payloads) to 1 MB, reducing risk of excessive allocations/DoS when reading malformed archives.

Changes:

  • Introduced a MaxMetadataBlockSize constant (1 MB) on TarHeader.
  • Updated the metadata ValidateSize() check to enforce the new maximum when reading PAX/GNU metadata blocks.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs Enforces the new 1 MB maximum via ValidateSize() before renting/reading metadata buffers.
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.cs Adds the MaxMetadataBlockSize constant used by the reader.

private const string GnuMagic = "ustar ";
private const string GnuVersion = " \0";

// // Maximum allowed size for metadata data sections (PAX extended attributes, GNU LongPath/LongLink).
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

The comment above MaxMetadataBlockSize has a duplicated comment marker (// //) and reads a bit oddly (“metadata data sections”). Consider fixing this to a single // and adjusting the wording to avoid repetition (e.g., “metadata sections” or “metadata data blocks”).

Suggested change
// // Maximum allowed size for metadata data sections (PAX extended attributes, GNU LongPath/LongLink).
// Maximum allowed size for metadata sections (PAX extended attributes, GNU LongPath/LongLink).

Copilot uses AI. Check for mistakes.
Comment on lines 720 to 725
private void ValidateSize()
{
if ((uint)_size > (uint)Array.MaxLength)
if ((uint)_size > (uint)MaxMetadataBlockSize)
{
ThrowSizeFieldTooLarge();
}
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

This introduces a new behavioral limit (1 MB) on PAX extended attribute blocks and GNU LongPath/LongLink metadata. Please add unit tests that exercise reading archives with metadata sections just over this limit and assert the expected exception is thrown (ideally for both sync and async paths, and at least one PAX and one GNU long-path case) so the limit doesn’t regress.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
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 in principle, are we sure 1MB is large enough to not break legitimate uses?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants