From d1fe8fade29a3bf60a2b57af83f18e94f1fd5b48 Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Mon, 3 Jul 2023 12:38:22 -0700 Subject: [PATCH 01/19] added _Py_normpathAndSize --- Include/internal/pycore_fileutils.h | 1 + Modules/posixmodule.c | 6 +++++- Python/fileutils.c | 12 +++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Include/internal/pycore_fileutils.h b/Include/internal/pycore_fileutils.h index ef6642d00f1b54..fd98d52517c6ea 100644 --- a/Include/internal/pycore_fileutils.h +++ b/Include/internal/pycore_fileutils.h @@ -253,6 +253,7 @@ extern int _Py_add_relfile(wchar_t *dirname, size_t bufsize); extern size_t _Py_find_basename(const wchar_t *filename); PyAPI_FUNC(wchar_t *) _Py_normpath(wchar_t *path, Py_ssize_t size); +PyAPI_FUNC(wchar_t *) _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *length); // The Windows Games API family does not provide these functions // so provide our own implementations. Remove them in case they get added diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index d73886f14cb9ec..82e62086497dfd 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -5275,7 +5275,11 @@ os__path_normpath_impl(PyObject *module, PyObject *path) if (!buffer) { return NULL; } - PyObject *result = PyUnicode_FromWideChar(_Py_normpath(buffer, len), -1); + Py_ssize_t end_len; + wchar_t *norm_path = _Py_normpathAndSize(buffer, len, &end_len); + printf("len: %d\n", len); + printf("end_len: %d\n", end_len); + PyObject *result = PyUnicode_FromWideChar(norm_path, -1); PyMem_Free(buffer); return result; } diff --git a/Python/fileutils.c b/Python/fileutils.c index f262c3e095c9ba..550369a6dfe9e7 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2379,7 +2379,7 @@ _Py_find_basename(const wchar_t *filename) the path, if known. If -1, the first null character will be assumed to be the end of the path. */ wchar_t * -_Py_normpath(wchar_t *path, Py_ssize_t size) +_Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *length) { assert(path != NULL); if (!path[0] || size == 0) { @@ -2447,8 +2447,11 @@ _Py_normpath(wchar_t *path, Py_ssize_t size) } #endif /* MS_WINDOWS */ + *length = size; + /* if pEnd is specified, check that. Else, check for null terminator */ for (; !IS_END(p1); ++p1) { + *length++; wchar_t c = *p1; #ifdef ALTSEP if (c == ALTSEP) { @@ -2502,6 +2505,13 @@ _Py_normpath(wchar_t *path, Py_ssize_t size) return path; } +wchar_t * +_Py_normpath(wchar_t *path, Py_ssize_t size) +{ + Py_ssize_t length; + return _Py_normpathAndSize(path, size, &length); +} + /* Get the current directory. buflen is the buffer size in wide characters including the null character. Decode the path from the locale encoding. From 8cab42c5cca34c5c272e9f0dd7704a6b9a580eac Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Wed, 5 Jul 2023 12:45:24 -0700 Subject: [PATCH 02/19] PyAPI_FUNC -> extern --- Include/internal/pycore_fileutils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/internal/pycore_fileutils.h b/Include/internal/pycore_fileutils.h index fd98d52517c6ea..bb8a70e36a8513 100644 --- a/Include/internal/pycore_fileutils.h +++ b/Include/internal/pycore_fileutils.h @@ -253,7 +253,7 @@ extern int _Py_add_relfile(wchar_t *dirname, size_t bufsize); extern size_t _Py_find_basename(const wchar_t *filename); PyAPI_FUNC(wchar_t *) _Py_normpath(wchar_t *path, Py_ssize_t size); -PyAPI_FUNC(wchar_t *) _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *length); +extern wchar_t *_Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *length); // The Windows Games API family does not provide these functions // so provide our own implementations. Remove them in case they get added From 82a9d360a248a26dff340113db5a3b40407ed7ed Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Wed, 5 Jul 2023 12:45:47 -0700 Subject: [PATCH 03/19] remove prinfs --- Modules/posixmodule.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index af40e2ce8b98bc..ce259aa562a950 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -5273,11 +5273,9 @@ os__path_normpath_impl(PyObject *module, PyObject *path) if (!buffer) { return NULL; } - Py_ssize_t end_len; - wchar_t *norm_path = _Py_normpathAndSize(buffer, len, &end_len); - printf("len: %d\n", len); - printf("end_len: %d\n", end_len); - PyObject *result = PyUnicode_FromWideChar(norm_path, -1); + Py_ssize_t norm_len; + wchar_t *norm_path = _Py_normpathAndSize(buffer, len, &norm_len); + PyObject *result = PyUnicode_FromWideChar(norm_path, norm_len); PyMem_Free(buffer); return result; } From 6c18bf8d10b8688c05ab2c0b98e4a5b8e116f91a Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Wed, 5 Jul 2023 12:46:16 -0700 Subject: [PATCH 04/19] fix length calculation --- Python/fileutils.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index 550369a6dfe9e7..9347ae63112c3e 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2447,11 +2447,8 @@ _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *length) } #endif /* MS_WINDOWS */ - *length = size; - /* if pEnd is specified, check that. Else, check for null terminator */ for (; !IS_END(p1); ++p1) { - *length++; wchar_t c = *p1; #ifdef ALTSEP if (c == ALTSEP) { @@ -2499,6 +2496,11 @@ _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *length) *p2 = L'\0'; } } + if (path == p2) { + *length = 0; + } else{ + *length = p2 - path + 1; + } #undef SEP_OR_END #undef IS_SEP #undef IS_END From c90249de10d3ccbc6ff6f788130a4187f20ff546 Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Thu, 6 Jul 2023 11:53:11 -0700 Subject: [PATCH 05/19] length -> norm_size, fix begining null char case --- Python/fileutils.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index 9347ae63112c3e..d2aa64f90e894b 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2379,10 +2379,11 @@ _Py_find_basename(const wchar_t *filename) the path, if known. If -1, the first null character will be assumed to be the end of the path. */ wchar_t * -_Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *length) +_Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *norm_size) { assert(path != NULL); - if (!path[0] || size == 0) { + if (!path[0] && size < 0 || size == 0) { + *norm_size = 0; return path; } wchar_t *pEnd = size >= 0 ? &path[size] : NULL; @@ -2497,9 +2498,9 @@ _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *length) } } if (path == p2) { - *length = 0; + *norm_size = 0; } else{ - *length = p2 - path + 1; + *norm_size = p2 - path + 1; } #undef SEP_OR_END #undef IS_SEP @@ -2510,8 +2511,8 @@ _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *length) wchar_t * _Py_normpath(wchar_t *path, Py_ssize_t size) { - Py_ssize_t length; - return _Py_normpathAndSize(path, size, &length); + Py_ssize_t norm_length; + return _Py_normpathAndSize(path, size, &norm_length); } From 8e1f1ea5456fd2c1796346d9dd45c1dc68000fb2 Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Thu, 6 Jul 2023 12:33:58 -0700 Subject: [PATCH 06/19] fix norm_size calculation --- Python/fileutils.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index d2aa64f90e894b..d962650b981d0b 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2497,11 +2497,7 @@ _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *norm_size) *p2 = L'\0'; } } - if (path == p2) { - *norm_size = 0; - } else{ - *norm_size = p2 - path + 1; - } + *norm_size = p2 - path + 1; #undef SEP_OR_END #undef IS_SEP #undef IS_END From 30038913b66a89a42cd2348a9bfd080b2c36913d Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Thu, 6 Jul 2023 12:34:15 -0700 Subject: [PATCH 07/19] add test cases --- Lib/test/test_ntpath.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index 538d758624c9d6..2154f47f0019da 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -355,6 +355,12 @@ def test_normpath(self): tester("ntpath.normpath('\\\\foo')", '\\\\foo') tester("ntpath.normpath('\\\\')", '\\\\') + # gh-106242: don't truncate null characters in path + tester("ntpath.normpath('foo\x00bar')", 'foo\x00bar') + tester("ntpath.normpath('\x00\x00')", '\x00\x00') + tester("ntpath.normpath('\x00foo')", '\x00foo') + tester("ntpath.normpath('\x00')", '\x00') + def test_realpath_curdir(self): expected = ntpath.normpath(os.getcwd()) tester("ntpath.realpath('.')", expected) From 30fa3a40c3325f2050434169465bc96793f91e17 Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Thu, 6 Jul 2023 15:53:06 -0700 Subject: [PATCH 08/19] move tests to test_genericpath.py --- Lib/test/test_genericpath.py | 4 ++++ Lib/test/test_ntpath.py | 6 ------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py index 489044f8090d3b..4f311c2d498e9f 100644 --- a/Lib/test/test_genericpath.py +++ b/Lib/test/test_genericpath.py @@ -460,6 +460,10 @@ def test_normpath_issue5827(self): for path in ('', '.', '/', '\\', '///foo/.//bar//'): self.assertIsInstance(self.pathmodule.normpath(path), str) + def test_normpath_issue106242(self): + for path in ('\x00', 'foo\x00bar', '\x00\x00', '\x00foo', 'foo\x00'): + self.assertEqual(self.pathmodule.normpath(path), path) + def test_abspath_issue3426(self): # Check that abspath returns unicode when the arg is unicode # with both ASCII and non-ASCII cwds. diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index 2154f47f0019da..538d758624c9d6 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -355,12 +355,6 @@ def test_normpath(self): tester("ntpath.normpath('\\\\foo')", '\\\\foo') tester("ntpath.normpath('\\\\')", '\\\\') - # gh-106242: don't truncate null characters in path - tester("ntpath.normpath('foo\x00bar')", 'foo\x00bar') - tester("ntpath.normpath('\x00\x00')", '\x00\x00') - tester("ntpath.normpath('\x00foo')", '\x00foo') - tester("ntpath.normpath('\x00')", '\x00') - def test_realpath_curdir(self): expected = ntpath.normpath(os.getcwd()) tester("ntpath.realpath('.')", expected) From f0afe44906c9a2dce62e580480fa349a0c6ed71a Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Thu, 6 Jul 2023 15:53:53 -0700 Subject: [PATCH 09/19] handle edge cases --- Python/fileutils.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Python/fileutils.c b/Python/fileutils.c index d962650b981d0b..9d84e0ba57c391 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2498,6 +2498,11 @@ _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *norm_size) } } *norm_size = p2 - path + 1; + if (path == p2 && *norm_size < size && path[0] == L'\0') { + *norm_size = 0; + } else if (size > 0 && *norm_size > size) { + *norm_size = size; + } #undef SEP_OR_END #undef IS_SEP #undef IS_END From 641290104d332aa29e18866233bf612a3dffdce1 Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Thu, 13 Jul 2023 12:42:10 -0700 Subject: [PATCH 10/19] decrement p2 when == minp2 & update minp2 handling with leading ./ --- Python/fileutils.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index 9d84e0ba57c391..4d519e8fa7f536 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2432,11 +2432,7 @@ _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *norm_size) *p2++ = lastC = *p1; } } - if (sepCount) { - minP2 = p2; // Invalid path - } else { - minP2 = p2 - 1; // Absolute path has SEP at minP2 - } + minP2 = p2 - 1; } #else // Skip past two leading SEPs @@ -2496,13 +2492,10 @@ _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *norm_size) while (--p2 != minP2 && *p2 == SEP) { *p2 = L'\0'; } + } else { + --p2; } *norm_size = p2 - path + 1; - if (path == p2 && *norm_size < size && path[0] == L'\0') { - *norm_size = 0; - } else if (size > 0 && *norm_size > size) { - *norm_size = size; - } #undef SEP_OR_END #undef IS_SEP #undef IS_END From 78192de7abce32052a44068b24bda53dadf91ec5 Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Thu, 13 Jul 2023 12:43:07 -0700 Subject: [PATCH 11/19] change test case to no longer include null character --- Lib/test/test_site.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py index 9e701fd847acdf..79f28ec4d178aa 100644 --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -172,14 +172,14 @@ def test_addpackage_empty_lines(self): def test_addpackage_import_bad_pth_file(self): # Issue 5258 - pth_dir, pth_fn = self.make_pth("abc\x00def\n") + pth_dir, pth_fn = self.make_pth("abc<>$$**:://def\n") with captured_stderr() as err_out: self.assertFalse(site.addpackage(pth_dir, pth_fn, set())) self.maxDiff = None self.assertEqual(err_out.getvalue(), "") for path in sys.path: if isinstance(path, str): - self.assertNotIn("abc\x00def", path) + self.assertNotIn("abc<>$$**:://def", path) def test_addsitedir(self): # Same tests for test_addpackage since addsitedir() essentially just From 4b9de2cacb35d55aef4cbbdb6a34e364cf583aaf Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Thu, 13 Jul 2023 16:17:37 -0700 Subject: [PATCH 12/19] Add norm_size variable description, add normpath description --- Python/fileutils.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index 4d519e8fa7f536..a4e2c340203c54 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2377,7 +2377,8 @@ _Py_find_basename(const wchar_t *filename) path, which will be within the original buffer. Guaranteed to not make the path longer, and will not fail. 'size' is the length of the path, if known. If -1, the first null character will be assumed - to be the end of the path. */ + to be the end of the path. 'norm_size' is a pointer to a variable + containing the length of the resulting normalized path. */ wchar_t * _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *norm_size) { @@ -2502,6 +2503,11 @@ _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *norm_size) return path; } +/* In-place path normalisation. Returns the start of the normalized + path, which will be within the original buffer. Guaranteed to not + make the path longer, and will not fail. 'size' is the length of + the path, if known. If -1, the first null character will be assumed + to be the end of the path. */ wchar_t * _Py_normpath(wchar_t *path, Py_ssize_t size) { From f1731f1f093a951d587cfbacba71c2b405141480 Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Thu, 13 Jul 2023 16:20:19 -0700 Subject: [PATCH 13/19] update normpathAndSize description --- Python/fileutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index a4e2c340203c54..bf0bbf06b7feab 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2378,7 +2378,7 @@ _Py_find_basename(const wchar_t *filename) make the path longer, and will not fail. 'size' is the length of the path, if known. If -1, the first null character will be assumed to be the end of the path. 'norm_size' is a pointer to a variable - containing the length of the resulting normalized path. */ + that will be set to the length of the resulting normalized path. */ wchar_t * _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *norm_size) { From d7f70457dc51973ffb47dd653c0c221085f00ca0 Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Sat, 15 Jul 2023 17:19:22 -0700 Subject: [PATCH 14/19] norm_size->normsize --- Python/fileutils.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index bf0bbf06b7feab..ea363bb124ef22 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2377,14 +2377,14 @@ _Py_find_basename(const wchar_t *filename) path, which will be within the original buffer. Guaranteed to not make the path longer, and will not fail. 'size' is the length of the path, if known. If -1, the first null character will be assumed - to be the end of the path. 'norm_size' is a pointer to a variable - that will be set to the length of the resulting normalized path. */ + to be the end of the path. 'normsize' will be set to contain the + length of the resulting normalized path. */ wchar_t * -_Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *norm_size) +_Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *normsize) { assert(path != NULL); if (!path[0] && size < 0 || size == 0) { - *norm_size = 0; + *normsize = 0; return path; } wchar_t *pEnd = size >= 0 ? &path[size] : NULL; @@ -2496,7 +2496,7 @@ _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *norm_size) } else { --p2; } - *norm_size = p2 - path + 1; + *normsize = p2 - path + 1; #undef SEP_OR_END #undef IS_SEP #undef IS_END From 9e0d52a25182691497a0522b5402574ad811bd5b Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Sat, 15 Jul 2023 18:14:21 -0700 Subject: [PATCH 15/19] remove trailing whitespace --- Python/fileutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index ea363bb124ef22..37d012e72d4856 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2377,7 +2377,7 @@ _Py_find_basename(const wchar_t *filename) path, which will be within the original buffer. Guaranteed to not make the path longer, and will not fail. 'size' is the length of the path, if known. If -1, the first null character will be assumed - to be the end of the path. 'normsize' will be set to contain the + to be the end of the path. 'normsize' will be set to contain the length of the resulting normalized path. */ wchar_t * _Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *normsize) From 3ef9e3b1e12f316fd5b04f536486db882d19149b Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Mon, 17 Jul 2023 12:09:37 -0700 Subject: [PATCH 16/19] _Py_normpathAndSize -> _Py_normpath_and_size --- Include/internal/pycore_fileutils.h | 2 +- Modules/posixmodule.c | 2 +- Python/fileutils.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Include/internal/pycore_fileutils.h b/Include/internal/pycore_fileutils.h index bb8a70e36a8513..9d873fc7df4c37 100644 --- a/Include/internal/pycore_fileutils.h +++ b/Include/internal/pycore_fileutils.h @@ -253,7 +253,7 @@ extern int _Py_add_relfile(wchar_t *dirname, size_t bufsize); extern size_t _Py_find_basename(const wchar_t *filename); PyAPI_FUNC(wchar_t *) _Py_normpath(wchar_t *path, Py_ssize_t size); -extern wchar_t *_Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *length); +extern wchar_t *_Py_normpath_and_size(wchar_t *path, Py_ssize_t size, Py_ssize_t *length); // The Windows Games API family does not provide these functions // so provide our own implementations. Remove them in case they get added diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 533b5c8753f181..e9b2fced826ff6 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -5275,7 +5275,7 @@ os__path_normpath_impl(PyObject *module, PyObject *path) return NULL; } Py_ssize_t norm_len; - wchar_t *norm_path = _Py_normpathAndSize(buffer, len, &norm_len); + wchar_t *norm_path = _Py_normpath_and_size(buffer, len, &norm_len); PyObject *result = PyUnicode_FromWideChar(norm_path, norm_len); PyMem_Free(buffer); return result; diff --git a/Python/fileutils.c b/Python/fileutils.c index 37d012e72d4856..2af8c2fa6b23eb 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2380,7 +2380,7 @@ _Py_find_basename(const wchar_t *filename) to be the end of the path. 'normsize' will be set to contain the length of the resulting normalized path. */ wchar_t * -_Py_normpathAndSize(wchar_t *path, Py_ssize_t size, Py_ssize_t *normsize) +_Py_normpath_and_size(wchar_t *path, Py_ssize_t size, Py_ssize_t *normsize) { assert(path != NULL); if (!path[0] && size < 0 || size == 0) { @@ -2512,7 +2512,7 @@ wchar_t * _Py_normpath(wchar_t *path, Py_ssize_t size) { Py_ssize_t norm_length; - return _Py_normpathAndSize(path, size, &norm_length); + return _Py_normpath_and_size(path, size, &norm_length); } From c885d13975ec9fefdb2ae34d5ea63184cd28ea87 Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Mon, 17 Jul 2023 16:19:09 -0700 Subject: [PATCH 17/19] revert test_addpackage_import_bad_pth_file change --- Lib/test/test_site.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py index 79f28ec4d178aa..9e701fd847acdf 100644 --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -172,14 +172,14 @@ def test_addpackage_empty_lines(self): def test_addpackage_import_bad_pth_file(self): # Issue 5258 - pth_dir, pth_fn = self.make_pth("abc<>$$**:://def\n") + pth_dir, pth_fn = self.make_pth("abc\x00def\n") with captured_stderr() as err_out: self.assertFalse(site.addpackage(pth_dir, pth_fn, set())) self.maxDiff = None self.assertEqual(err_out.getvalue(), "") for path in sys.path: if isinstance(path, str): - self.assertNotIn("abc<>$$**:://def", path) + self.assertNotIn("abc\x00def", path) def test_addsitedir(self): # Same tests for test_addpackage since addsitedir() essentially just From 0959e2b56e2814afe7e630275e1ab2fdf56809d4 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 14 Aug 2023 23:11:12 +0000 Subject: [PATCH 18/19] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-08-14-23-11-11.gh-issue-106242.71HMym.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-08-14-23-11-11.gh-issue-106242.71HMym.rst diff --git a/Misc/NEWS.d/next/Library/2023-08-14-23-11-11.gh-issue-106242.71HMym.rst b/Misc/NEWS.d/next/Library/2023-08-14-23-11-11.gh-issue-106242.71HMym.rst new file mode 100644 index 00000000000000..c742e58bfc4d8d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-08-14-23-11-11.gh-issue-106242.71HMym.rst @@ -0,0 +1 @@ +Fixes :func:`os.normpath` to handle embedded null characters without truncating the path. From aecae846fff0a15585178d61cdc44cae1b91bb76 Mon Sep 17 00:00:00 2001 From: Finn Womack Date: Mon, 14 Aug 2023 16:18:34 -0700 Subject: [PATCH 19/19] Update Misc/NEWS.d/next/Library/2023-08-14-23-11-11.gh-issue-106242.71HMym.rst Co-authored-by: Steve Dower --- .../next/Library/2023-08-14-23-11-11.gh-issue-106242.71HMym.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-08-14-23-11-11.gh-issue-106242.71HMym.rst b/Misc/NEWS.d/next/Library/2023-08-14-23-11-11.gh-issue-106242.71HMym.rst index c742e58bfc4d8d..44237a9f15708c 100644 --- a/Misc/NEWS.d/next/Library/2023-08-14-23-11-11.gh-issue-106242.71HMym.rst +++ b/Misc/NEWS.d/next/Library/2023-08-14-23-11-11.gh-issue-106242.71HMym.rst @@ -1 +1 @@ -Fixes :func:`os.normpath` to handle embedded null characters without truncating the path. +Fixes :func:`os.path.normpath` to handle embedded null characters without truncating the path.