Skip to content
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 does not support absolute paths #338

Open
iUnknwn opened this issue Apr 13, 2019 · 2 comments · May be fixed by #392
Open

TarEntry does not support absolute paths #338

iUnknwn opened this issue Apr 13, 2019 · 2 comments · May be fixed by #392
Labels
enhancement Feature request or other improvements of existing functionality tar Related to TAR file format

Comments

@iUnknwn
Copy link
Contributor

iUnknwn commented Apr 13, 2019

Currently, TarEntry.cs, in GetFileTarHeader, trims all leading forward slashes.

Trying to write /home/username/foo.txt as an entry would to write home/username/foo.txt

This prevents writing absolute paths to the archive, and also breaks the RootPath string, as the entry name will no longer have the root path as a sub string (if it was set to /home/username), so it will never match when the entry is added to the archive.

If we're trying to specifically avoid UNC path names, it might be easier to just test for a leading double back slash in the original path (instead of testing for leading slashes).

Expected behavior

RootPath should work as expected when adding absolute paths on POSIX.

Actual behavior

RootPath does not work as expected - file strings will never match RootPath because RootPath will still contain the leading '/', but the file entry will not.

Additionally, absolute file paths will be broken, regardless if root path is used.

Version of SharpZipLib

1.1.0

Obtained from (only keep the relevant lines)

  • Package installed using NuGet
iUnknwn added a commit to iUnknwn/SharpZipLib that referenced this issue Apr 13, 2019
For icsharpcode#337: removes the changes to path based on current working
directory. This prevents issues where files that are below the
current working directly will behave differently than those that
aren't.

For icsharpcode#338: Simply removes the code that would remove leading forward
slashes from paths. This should unbreak absolute POSIX paths, and avoid
the issue where RootPath wouldn't work, though it does allow
unc paths (which were previously blocked) as a potential side effect.

Part of the issue with icsharpcode#338 is any changes to the path, as part of
the TarEntry's GetFileTarHeader have the potential to break RootPath,
so you can't simply check for UNC path names there and modify.
@piksel piksel added the tar Related to TAR file format label Jun 18, 2019
iUnknwn added a commit to iUnknwn/SharpZipLib that referenced this issue Oct 31, 2019
For icsharpcode#337: removes the changes to path based on current working
directory. This prevents issues where files that are below the
current working directly will behave differently than those that
aren't.

For icsharpcode#338: Simply removes the code that would remove leading forward
slashes from paths. This should unbreak absolute POSIX paths, and avoid
the issue where RootPath wouldn't work, though it does allow
unc paths (which were previously blocked) as a potential side effect.

Part of the issue with icsharpcode#338 is any changes to the path, as part of
the TarEntry's GetFileTarHeader have the potential to break RootPath,
so you can't simply check for UNC path names there and modify.
@iUnknwn iUnknwn linked a pull request Oct 31, 2019 that will close this issue
@piksel
Copy link
Member

piksel commented Feb 1, 2020

Couldn't you just set the RootPath to "home/username"?

@piksel
Copy link
Member

piksel commented Nov 22, 2020

This is probably a duplicate of #38 (how fitting). But that one only contains dead links and not a clear description. Closing it in favor of this one.

@piksel piksel closed this as completed Nov 22, 2020
@piksel piksel reopened this Nov 22, 2020
@piksel piksel changed the title Tar does not handle POSIX absolute paths correctly (trims leading '/'), breaks RootPath TarEntry does not support absolute paths Nov 22, 2020
@piksel piksel added the enhancement Feature request or other improvements of existing functionality label Nov 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request or other improvements of existing functionality tar Related to TAR file format
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants