Skip to content

TarReader doesn't read paths with spaces from Pax extended attributes #78456

Closed
@prettybits

Description

@prettybits

Description

For tar archives with pax entries whose extended metadata contains a path with spaces that path is currently silently ignored and the standard name field used, which can lead to extraction errors when the names of headers aren't unique (e.g. I came across files that put "PaxHeader" as the name for every pax entry and their consecutive file entry.

Cannot create '/home/prettybits/tests/PaxHeader' because a file or directory with the 
same name already exists.

Spaces in values of extended metadata entries are explicitly treated as malformed here (introduced in #74281), but I can't see why. @stephentoub

Reproduction Steps

Given a tar file with multiple pax entries whose name field values for extended attribute and file entry each are "PaxHeader", and pax extended attributes which contain a path with spaces (e.g. 29 path=file with spaces.xml\n13 size=7720\n) :

using System.Formats.Tar;

TarFile.ExtractToDirectory(@"/home/prettybits/tests/paxheaders.tar", @"/home/prettybits/tests/", false);

=> Cannot create '/home/prettybits/tests/PaxHeader' because a file or directory with the same name already exists.

Expected behavior

Paths with spaces from pax extended attributes should be used as the name of the logical entry.

Actual behavior

Paths with spaces are ignored and the original name used, which might not be unique.

Regression?

Reading the diff, this likely worked correctly before #74281 was merged.

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions