-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
os.path.normpath truncates input on null bytes in 3.11, but not 3.10 #106242
Comments
I think this is a matter of documentation. I don't recall whether Steve Dower (@zooba), the author of the C implementation of
Since the
Footnotes
|
It's probably easiest just to make
I think that fix can be backported. As noted, the path is invalid anyway, but probably best to preserve behaviour rather than double-down on changing it. |
Thanks! I think maintaining the 3.10 behaviour makes sense, but that if one wanted to double down on a change instead, then a FWIW I notice on Windows, we get truncation on Python 3.11, no truncation on Python3.10, and a ValueError on Python 3.8 (didn't test 3.9). So there is some precedent for a My use case is that I'm passing filepaths over a socket to another process, and since null bytes can't appear in filepaths, I'm using nulls as the delimiter. I was converting the paths to absolute paths with |
Raising
On Windows,
Python 3.10: >>> os.getcwd()
'C:\\Windows'
>>> os.path.abspath('E:spam')
'E:\\Temp\\spam'
>>> os.path.abspath('E:spam\0')
'E:spam\x00' The result Python 3.11: >>> os.getcwd()
'C:\\Windows'
>>> os.path.abspath('E:spam')
'E:\\Temp\\spam'
>>> os.path.abspath('E:spam\0')
'E:\\Temp\\spam' The new behavior of
Your workaround is how I would have implemented it from the start. |
Apologies, I'm an idiot - for some reason my fingers typed Being more careful with my typing: I see I see I can see that as you said, on Python 3.8 and 3.10, Similarly, with So it's |
The behavior of |
is there anything left to be done here? additional testing and possible other API corner case fixes based on Eryksun's comment? |
…when there are embedded nulls
Yes, I think |
…here are embedded nulls (GH-108248) * gh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls * Update 2023-08-22-00-36-57.gh-issue-106242.q24ITw.rst mention Windows and the former incorrect ValueError. --------- Co-authored-by: Gregory P. Smith <greg@krypto.org>
…when there are embedded nulls (pythonGH-108248) * pythongh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls * Update 2023-08-22-00-36-57.gh-issue-106242.q24ITw.rst mention Windows and the former incorrect ValueError. --------- (cherry picked from commit de33b5c) Co-authored-by: Steve Dower <steve.dower@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org>
…when there are embedded nulls (pythonGH-108248) * pythongh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls * Update 2023-08-22-00-36-57.gh-issue-106242.q24ITw.rst mention Windows and the former incorrect ValueError. --------- (cherry picked from commit de33b5c) Co-authored-by: Steve Dower <steve.dower@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org>
… when there are embedded nulls (GH-108248) (#108251) gh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls (GH-108248) * gh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls * Update 2023-08-22-00-36-57.gh-issue-106242.q24ITw.rst mention Windows and the former incorrect ValueError. --------- (cherry picked from commit de33b5c) Co-authored-by: Steve Dower <steve.dower@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org>
CVE-2023-41105 was assigned to this. There's also CVE-2023-40587 which is a CVE against pyramid, but it's about triggering this same issue. I wasn't involved in these assignments, posting here so it's logged in the GitHub issue. (CVE-2023-41105 is already tracked at https://github.com/psf/advisory-database) |
Bug report
Looks like
posix._path_normpath
has slightly different behaviour to the python implementation ofnormpath
defined inposixpath
, as suchos.path.normpath
behaves differently on Python 3.11 (whereposix._path_normpath
is used if it exists) vs 3.10 on posix systems:Python 3.10:
Python 3.11:
Obviously filepaths shouldn't have nulls in them, but the above means invalid input to a program could result in the wrong files or directories being used, rather than an error about embedded nulls once the filepaths are actually used for a system call. And I'm guessing the inconsistency between Python3.10 and 3.11, or between the Python and C implementations of
normpath
was not intended in any case.Your environment
CPython 3.11.3, running on Arch Linux
Python 3.11.3 (main, Jun 5 2023, 09:32:32) [GCC 13.1.1 20230429] on linux
Linked PRs
The text was updated successfully, but these errors were encountered: