| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
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 // -- that would turn symlink targets into UNC paths, where I'm not sure of the security implications, and anyway it's not something you'd find in a portable UNIX-based tarball. |
Sorry, something went wrong.
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 a problem hiding this comment.
OK; re-reading the duscussion I see experts suggesting to always replace, so let's go with that.
Sorry, something went wrong.
|
🤖 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.
| 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.
| 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.
|
Looks good! Could you also add an entry to Doc/whatsnew/3.15.rst? |
Sorry, something went wrong.
|
Thank you! |
Sorry, something went wrong.
|
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.
|
@picnixz if you open a revert PR as draft, you could use !buildbot to check this worker & see if it passes again? A |
Sorry, something went wrong.
|
I'm not on a dev session but I'll do it tomorrow if no one beats me to it. |
Sorry, something went wrong.
|
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.
|
Shouldn't the inverse normalization of path separator characters be done in tarfile.TarFile.add()? Otherwise, the symlink targets written in the tar archive are wrong when extracted on another platform (and I believe not conforming to the standard). See #151669. |
Sorry, something went wrong.
Which standard are you referring to?
Perhaps, but, I'm still fixing issues from the last time I changed long-standing behaviour in tarfile. |
Sorry, something went wrong.
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 / as the path separator (and this is what the tarfile module implements, with one exception). The current behavior of tarfile.TarFile.add() is to use native path separators for symlink targets. On Windows, this result in tar files that produce wrong symbolic links when extracted on POSIX platforms.
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 / as path separator. Maybe code like this can be fixed specifying a filter function that fixes the path separators on Windows. However, the exact same argument could have been made for the change in this PR. On the other hand, I don't see a way to fix tar archives produced by shutil.make_archive(). I think that having the normalization only on extract is the worst possible outcome as it introduces unnecessary asymmetry: users of the tarfile module need special treatment of symlinks on Windows when creating archives, but not when extracting them. |
Sorry, something went wrong.
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.
|
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 a\b as a symbolic link to the file a\b in the current directory. 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 linkpath The full path of the linked-to file. Note that this is encoded in UTF8 and can thus include non-ASCII characters. and https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_271 defines
|
Sorry, something went wrong.
|
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.
|
@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.
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 git archive + tarfile. That's about as strong a justification as one would need I think? The regression is fixed by gh-151671, which looks correct. |
Sorry, something went wrong.
|
If this is not fixed, I guess meson would have to vendor the tarfile module. 🤷 |
Sorry, something went wrong.
We will not, so don't bother suggesting it again. |
Sorry, something went wrong.
|
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.
|
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.
| Back | FazBrowse Home | New Git URL |
CC @encukou