GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-57911: Sanitize symlink targets in tarfile on win32 by wiomoc · Pull Request #138309 · python/cpython Conversation
|
|
Should this be done for hardlinks as well? I'd prefer saying “rewrite” rather than “sanitize”, as this is not fixing unsafe input. We should probably skip this for leading |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
This problem doesn't seam to occur when creating hardlinks: >>> os.mkdir("tmp") >>> os.mkdir("tmp\\child") >>> open("tmp\\child\\test.txt", "w").write("hello world") 11 >>> os.link("tmp/child/test.txt", "tmp/testlink.txt") >>> open("tmp\\testlink.txt").read() 'hello world'
On the one hand, I see the risk of security implications, but I also note that in pathlib, slashes are also replaced in UNC paths. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
OK; re-reading the duscussion I see experts suggesting to always replace, so let's go with that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
🤖 New build scheduled with the buildbot fleet by @encukou for commit 942b6e3 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F138309%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| When extracting tar files on Windows Posix flavoured path separators in symlink | ||
| targets will be replaced by backward-slashes to prevent corrupted links. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| When extracting tar files on Windows Posix flavoured path separators in symlink | |
| targets will be replaced by backward-slashes to prevent corrupted links. | |
| When extracting tar files on Windows, slashes in symlink | |
| targets will be replaced by backslashes to prevent corrupted links. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Looks good! Could you also add an entry to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thank you! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I think this broke some buildbots: https://buildbot.python.org/#/builders/914. It wasn't detected until #138276 (which was 20h ago, but this change is 2 days ago and the previous buildbot run was 3 days ago) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@picnixz if you open a revert PR as draft, you could use A |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm not on a dev session but I'll do it tomorrow if no one beats me to it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The test only fails, when running on a Windows system with disabled symlink support - therefore it didn't occure on GH actions. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Shouldn't the inverse normalization of path separator characters be done in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Which standard are you referring to?
Perhaps, but, I'm still fixing issues from the last time I changed long-standing behaviour in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The tar format definition. I haven't checked the format definition (and I don't even know whether it exists), but all paths in a tar file are usually stored with
Think to this as more fallout from these changes. The normalization has always been missing, but it broke my application only since this PR has been merged (and Windows support for symlinks is more widespread: I would not have noticed it if not for the fact that GitHub Actions Windows runners have support for symlink enabled).
tar archives produced by code like os.symlink("../baz", "foo") tar = tarfile.open("sample.tar", "w") tar.add("foo") tar.close() are currently invalid when created on Windows. In other words, they produce the wrong filesystem objects when extracted on a platform that uses Maybe code like this can be fixed specifying a I think that having the normalization only on extract is the worst possible outcome as it introduces unnecessary asymmetry: users of the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Could you check, then? An actual reference to the standard would make this an easy sell -- that would mean that relevant people already thought about this. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
The tar standard is a POSIX standard. POSIX does not make backslashes special in any way; they are a valid character in a file name. Therefore, POSIX treats a link name of For example, https://man.freebsd.org/cgi/man.cgi?query=tar&apropos=0&sektion=5&manpath=FreeBSD+7.0-RELEASE&arch=default&format=html has and https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_271 defines
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Found something in the POSIX standard as well (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13_06), where directory entry type 2 "represents a symbolic link. The contents of the symbolic link shall be stored in the linkname field." Within tar files, the contents of the symbolic link are best described in the linkpath extension record, which is defined as follows: "The pathname of a link being created to another file, of any type, previously archived. This record shall override the linkname field in the following ustar header block(s)." In other words, the target of a symbolic link in a tar file should indeed be a pathname, and as such separated by forward slashes. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @bonzini ! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@encukou I find the specification quotes by @bonzini clear in this respect. What is the best way to move this forward? I would love to see fix for this problem included in Python 3.15, if possible. That would avoid having to carry a downstream workaround for the issue we encountered testing with Python 3.15b2. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Since no one said it explicitly yet: this introduces a regression for sdist creation with meson-python on Windows under Python 3.15. It's likely that that also affects other build backends that rely on The regression is fixed by gh-151671, which looks correct. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
If this is not fixed, I guess meson would have to vendor the tarfile module. 🤷 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
We will not, so don't bother suggesting it again. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the standard links. I'm... not sure if I'd call any of them “the” tar standard; it looks like it's best to not talk about standards in this issue.
I see: mesonbuild/meson#15932 So, we have a regression. That gives us two options:
@hugovk, do you think we should add the feature to 3.15? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Let's try #151671 for 3.15. We can still revert during the beta, if more issues come up, and also during the RC. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.