You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TarFile fails to extract even when symbolic link references into the output directory #77303
I already have an open issue about TarFile not wanting to create symbolic links that point outside the output directory: #74140.
Triggered by #77096, I was curious to see if podman would have the same issue as docker.
I did:
$ podman pull hello-world
$ podman save hello-world -o hello-world.tar # uncompressed when saving a local image
The resulting archive fails to extract:
Unhandled exception. System.IO.IOException: Extracting the Tar entry '../8e128b102ca8161cb297e3aa73240b8e537af67422fd4c22bf43c296c91d13ad.tar' would have resulted in a link target outside the specified destination directory: '/tmp/bca4a72dc384466ab6abd59cc585bd5a'
at System.Formats.Tar.TarEntry.GetDestinationAndLinkPaths(String destinationDirectoryPath)
at System.Formats.Tar.TarEntry.ExtractRelativeToDirectoryAsync(String destinationDirectoryPath, Boolean overwrite, SortedDictionary`2 pendingModes, CancellationToken cancellationToken)
at System.Formats.Tar.TarFile.ExtractToDirectoryInternalAsync(Stream source, String destinationDirectoryPath, Boolean overwriteFiles, Boolean leaveOpen, CancellationToken cancellationToken)
at System.Formats.Tar.TarFile.ExtractToDirectoryInternalAsync(Stream source, String destinationDirectoryPath, Boolean overwriteFiles, Boolean leaveOpen, CancellationToken cancellationToken)
at Program.<Main>$(String[] args) in /tmp/console/Program.cs:line 6
at Program.<Main>(String[] args)
The symbolic link it considers problematic is actually still pointing inside the output directory.
These are the archive entries:
Ok, I see. It is a bug where we fail to recognize that symlink is in fact pointing to path inside the destination directory (../8e128b102ca8161cb297e3aa73240b8e537af67422fd4c22bf43c296c91d13ad.tar) and throw IOException.
Activity
am11 commentedon Oct 21, 2022
This is a duplicate of #74140, right?
podman-hello-world.tarcan be used as a test asset when we have the fix.tmds commentedon Oct 21, 2022
In that case, the symbolic link points outside the output directory.
Here, the symbolic target is still in the output directory.
am11 commentedon Oct 21, 2022
Ok, I see. It is a bug where we fail to recognize that symlink is in fact pointing to path inside the destination directory (
../8e128b102ca8161cb297e3aa73240b8e537af67422fd4c22bf43c296c91d13ad.tar) and throwIOException.am11 commentedon Oct 21, 2022
Untested, but I think:
runtime/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarEntry.cs
Line 352 in ddebaf5
should be:
linkTargetPath = GetSanitizedFullPath(fileDestinationPath, LinkName);orlinkTargetPath = GetSanitizedFullPath(Path.GetDirectoryName(fileDestinationPath), LinkName);