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-117596: Fix realpath ValueError on null byte #117573

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def realpath(filename, *, strict=False):
if not stat.S_ISLNK(st.st_mode):
path = newpath
continue
except OSError:
except (OSError, ValueError):
if strict:
raise
path = newpath
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,15 @@ def test_realpath_resolve_first(self):
safe_rmdir(ABSTFN + "/k")
safe_rmdir(ABSTFN)

@skip_if_ABSTFN_contains_backslash
def test_realpath_null_byte(self):
path_with_null_byte = ABSTFN + "/\x00"
try:
os.mkdir(ABSTFN)
self.assertEqual(realpath(path_with_null_byte), path_with_null_byte)
finally:
safe_rmdir(ABSTFN)

def test_relpath(self):
(real_getcwd, os.getcwd) = (os.getcwd, lambda: r"/home/user/bar")
try:
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ Benjamin Hodgson
Joerg-Cyril Hoehle
Douwe Hoekstra
Robert Hoelzl
Stefan Hoelzl
Gregor Hoffleit
Chris Hoffman
Tim Hoffmann
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :exc:`ValueError` when :func:`os.path.realpath` is called with a path containing a null byte. Patch by Stefan Hoelzl.
Loading