Skip to content

TarFile fails to extract even when symbolic link references into the output directory #77303

Closed

Description

@tmds

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:

8e128b102ca8161cb297e3aa73240b8e537af67422fd4c22bf43c296c91d13ad.tar(RegularFile) -> 
c0e8b50899a56dcd91634bfbb7a8336f2c0f6f6a9bbb5ad9b747dc1547aaa9f4.json(RegularFile) -> 
00335d90e4f471aae0fdbae54765dd7a5a1cb276c55c2fc75bf64ab20c5c97d1/layer.tar(SymbolicLink) -> ../8e128b102ca8161cb297e3aa73240b8e537af67422fd4c22bf43c296c91d13ad.tar
00335d90e4f471aae0fdbae54765dd7a5a1cb276c55c2fc75bf64ab20c5c97d1/VERSION(RegularFile) -> 
00335d90e4f471aae0fdbae54765dd7a5a1cb276c55c2fc75bf64ab20c5c97d1/json(RegularFile) -> 
manifest.json(RegularFile) -> 
repositories(RegularFile) -> 

cc @carlossanlop @jozkee @am11

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Oct 21, 2022
  2. am11 commented on Oct 21, 2022

    @am11
    Member

    This is a duplicate of #74140, right? podman-hello-world.tar can be used as a test asset when we have the fix.

  3. tmds commented on Oct 21, 2022

    @tmds
    MemberAuthor

    This is a duplicate of #74140, right?

    In that case, the symbolic link points outside the output directory.
    Here, the symbolic target is still in the output directory.

  4. am11 commented on Oct 21, 2022

    @am11
    Member

    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.

  5. am11 commented on Oct 21, 2022

    @am11
    Member

    Untested, but I think:

    linkTargetPath = GetSanitizedFullPath(destinationDirectoryPath, LinkName);

    should be: linkTargetPath = GetSanitizedFullPath(fileDestinationPath, LinkName); or linkTargetPath = GetSanitizedFullPath(Path.GetDirectoryName(fileDestinationPath), LinkName);

  6. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Oct 22, 2022
  7. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Nov 11, 2022
  8. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 11, 2022
  9. added this to the 8.0.0 milestone on Nov 17, 2022
  10. ghost locked as resolved and limited conversation to collaborators on Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions