|
| 1 | +From 351d71b3c284eef7e381cc42b1a9d545142ed095 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Seth Michael Larson <seth@python.org> |
| 3 | +Date: Fri, 30 Jan 2026 09:49:11 -0600 |
| 4 | +Subject: [PATCH] Use os.path.commonpath() instead of commonprefix() |
| 5 | + |
| 6 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 7 | +Upstream-reference: https://github.com/pypa/pip/commit/8e227a9be4faa9594e05d02ca05a413a2a4e7735.patch |
| 8 | +--- |
| 9 | + src/pip/_internal/utils/unpacking.py | 2 +- |
| 10 | + tests/unit/test_utils_unpacking.py | 2 ++ |
| 11 | + 2 files changed, 3 insertions(+), 1 deletion(-) |
| 12 | + |
| 13 | +diff --git a/src/pip/_internal/utils/unpacking.py b/src/pip/_internal/utils/unpacking.py |
| 14 | +index 03467e8..6bda973 100644 |
| 15 | +--- a/src/pip/_internal/utils/unpacking.py |
| 16 | ++++ b/src/pip/_internal/utils/unpacking.py |
| 17 | +@@ -82,7 +82,7 @@ def is_within_directory(directory: str, target: str) -> bool: |
| 18 | + abs_directory = os.path.abspath(directory) |
| 19 | + abs_target = os.path.abspath(target) |
| 20 | + |
| 21 | +- prefix = os.path.commonprefix([abs_directory, abs_target]) |
| 22 | ++ prefix = os.path.commonpath([abs_directory, abs_target]) |
| 23 | + return prefix == abs_directory |
| 24 | + |
| 25 | + |
| 26 | +diff --git a/tests/unit/test_utils_unpacking.py b/tests/unit/test_utils_unpacking.py |
| 27 | +index d681fcb..313bd9e 100644 |
| 28 | +--- a/tests/unit/test_utils_unpacking.py |
| 29 | ++++ b/tests/unit/test_utils_unpacking.py |
| 30 | +@@ -412,6 +412,8 @@ def test_unpack_tar_unicode(tmpdir: Path) -> None: |
| 31 | + (("parent/", "parent/sub"), True), |
| 32 | + # Test target outside parent |
| 33 | + (("parent/", "parent/../sub"), False), |
| 34 | ++ # Test target sub-string of parent |
| 35 | ++ (("parent/child", "parent/childfoo"), False), |
| 36 | + ], |
| 37 | + ) |
| 38 | + def test_is_within_directory(args: Tuple[str, str], expected: bool) -> None: |
| 39 | +-- |
| 40 | +2.45.4 |
| 41 | + |
0 commit comments