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

gh-106242: Fix path truncation in normpath #106816

Merged
merged 27 commits into from
Aug 15, 2023
Merged

gh-106242: Fix path truncation in normpath #106816

merged 27 commits into from
Aug 15, 2023

Conversation

finnagin
Copy link
Contributor

@finnagin finnagin commented Jul 17, 2023

Following the suggestion from this comment in the original issue this PR adds a new function _Py_normpathAndSize which behaves like _Py_normpath but also takes a pointer which it will use to store the length of the final normalized path. This new function is then used in os__path_normpath_impl to pass the above mentioned length into PyUnicode_FromWideChar instead of -1.

Additionally, this adds a test to check that normpath is not truncating paths containing a null character as well as changes test_addpackage_import_bad_pth_file in test_site.py which was using a null character to make a bad path, specifically it was using the string 'abc\x00def'. The problem is that before this change this was being truncated for parts of the test so the string it was actually using in those parts was 'abc'. Upon making the normpath changes it started throwing the error ValueError: embedded null character so I changed the test to use 'abc<>$$**:://def' instead.

Copy link
Member

@zooba zooba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the minor name convention update

Include/internal/pycore_fileutils.h Outdated Show resolved Hide resolved
Include/internal/pycore_fileutils.h Outdated Show resolved Hide resolved
Lib/test/test_site.py Outdated Show resolved Hide resolved
@zooba
Copy link
Member

zooba commented Aug 14, 2023

Looks like we just need the NEWS entry - click "Details" next to the failed check for info on it (or run PCbuild/blurb.bat to create it locally).

Text should be something like ``Fixes :func:os.normpath to handle embedded null characters without truncating the path.` and put it under Library.

…1HMym.rst

Co-authored-by: Steve Dower <steve.dower@microsoft.com>
@zooba zooba merged commit 0932272 into python:main Aug 15, 2023
19 checks passed
@zooba zooba added needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels Aug 15, 2023
@miss-islington
Copy link
Contributor

Thanks @finnagin for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks @finnagin for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @finnagin and @zooba, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 09322724319d4c23195300b222a1c0ea720af56b 3.11

@miss-islington
Copy link
Contributor

Sorry, @finnagin and @zooba, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 09322724319d4c23195300b222a1c0ea720af56b 3.12

@bedevere-bot
Copy link

GH-107981 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 bug and security fixes label Aug 15, 2023
@bedevere-bot
Copy link

GH-107982 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Aug 15, 2023
zooba pushed a commit to zooba/cpython that referenced this pull request Aug 15, 2023
zooba pushed a commit to zooba/cpython that referenced this pull request Aug 15, 2023
ambv pushed a commit that referenced this pull request Aug 15, 2023
iritkatriel pushed a commit to iritkatriel/cpython that referenced this pull request Aug 16, 2023
Yhg1s pushed a commit that referenced this pull request Aug 16, 2023
…#107981)

* gh-106242: Fix path truncation in os.path.normpath (GH-106816)
* gh-106242: Minor fixup to avoid compiler warnings

---------

Co-authored-by: Finn Womack <flan313@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants