-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
TarEntry: remove some unneeded checks when extracting symbolic and hard links. #85378
Conversation
Tagging subscribers to this area: @dotnet/area-system-formats-tar Issue DetailsFixes #78695. @dotnet/area-system-io ptal.
|
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarEntry.cs
Outdated
Show resolved
Hide resolved
The LinkName for hard links is a path relative to the archive root.
@carlossanlop @jeffhandley @dotnet/area-system-io-compression can we try to get this reviewed in the coming weeks? |
@jozkee said he can take a look |
} | ||
else if (EntryType is TarEntryType.HardLink) | ||
{ | ||
// LinkName is path relative to the destinationDirectoryPath. |
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.
How can we assume that LinkName will never be an absolute path for hard links?
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.
We're using Path.Join
to interpret the LinkName
as a relative path.
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.
Someone could use a TarWriter
to manually write a Hard Link entry with LinkName = "C:\my\absolute\path". I don't think is something worth validating because likely no tools would produce it but is something to have in mind.
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarEntry.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.ExtractToDirectory.Stream.Tests.cs
Show resolved
Hide resolved
if (linkTargetPath == null) | ||
{ | ||
throw new IOException(SR.Format(SR.TarExtractingResultsLinkOutside, linkName, destinationDirectoryPath)); | ||
} |
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.
What do we do if the hard link target does not exist at the moment of extraction i.e: on CreateNonRegularFile
? I expect that the respective syscall fails.
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.
Yes it fails, and that is the proper thing to do.
Hard links are detected and handled by the tar writer. It won't include a hard link before the target file.
note: .NET's tar writer doesn't detect hard links and treats them like regular files. There is an open issue to handle them: #74404.
@jozkee thanks for the review! I've updated the PR based on your feedback. ptal. |
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.
LGTM, thanks!
Fixes #78695.
@dotnet/area-system-io ptal.