diff options
Diffstat (limited to 'meta/recipes-devtools/python/python3-zipp/0001-Add-SanitizedNames-mixin.patch')
| -rw-r--r-- | meta/recipes-devtools/python/python3-zipp/0001-Add-SanitizedNames-mixin.patch | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/meta/recipes-devtools/python/python3-zipp/0001-Add-SanitizedNames-mixin.patch b/meta/recipes-devtools/python/python3-zipp/0001-Add-SanitizedNames-mixin.patch new file mode 100644 index 0000000000..a352e7b9bd --- /dev/null +++ b/meta/recipes-devtools/python/python3-zipp/0001-Add-SanitizedNames-mixin.patch | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | From ef2227e35d1ae833b7bfa1674a45f58c732ae1a6 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: "Jason R. Coombs" <jaraco@jaraco.com> | ||
| 3 | Date: Wed, 27 Nov 2024 23:27:57 -0800 | ||
| 4 | Subject: [PATCH 1/5] Add SanitizedNames mixin. | ||
| 5 | |||
| 6 | Upstream-Status: Backport [https://github.com/jaraco/zipp/commit/564fcc10cdbfdaecdb33688e149827465931c9e0] | ||
| 7 | CVE: CVE-2024-5569 | ||
| 8 | Rebase to v3.7.0 | ||
| 9 | Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com> | ||
| 10 | --- | ||
| 11 | zipp.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 12 | 1 file changed, 62 insertions(+) | ||
| 13 | |||
| 14 | diff --git a/zipp.py b/zipp.py | ||
| 15 | index 26b723c..8f0950f 100644 | ||
| 16 | --- a/zipp.py | ||
| 17 | +++ b/zipp.py | ||
| 18 | @@ -68,6 +68,68 @@ def _difference(minuend, subtrahend): | ||
| 19 | return itertools.filterfalse(set(subtrahend).__contains__, minuend) | ||
| 20 | |||
| 21 | |||
| 22 | +class SanitizedNames: | ||
| 23 | + """ | ||
| 24 | + ZipFile mix-in to ensure names are sanitized. | ||
| 25 | + """ | ||
| 26 | + | ||
| 27 | + def namelist(self): | ||
| 28 | + return list(map(self._sanitize, super().namelist())) | ||
| 29 | + | ||
| 30 | + @staticmethod | ||
| 31 | + def _sanitize(name): | ||
| 32 | + r""" | ||
| 33 | + Ensure a relative path with posix separators and no dot names. | ||
| 34 | + | ||
| 35 | + Modeled after | ||
| 36 | + https://github.com/python/cpython/blob/bcc1be39cb1d04ad9fc0bd1b9193d3972835a57c/Lib/zipfile/__init__.py#L1799-L1813 | ||
| 37 | + but provides consistent cross-platform behavior. | ||
| 38 | + | ||
| 39 | + >>> san = SanitizedNames._sanitize | ||
| 40 | + >>> san('/foo/bar') | ||
| 41 | + 'foo/bar' | ||
| 42 | + >>> san('//foo.txt') | ||
| 43 | + 'foo.txt' | ||
| 44 | + >>> san('foo/.././bar.txt') | ||
| 45 | + 'foo/bar.txt' | ||
| 46 | + >>> san('foo../.bar.txt') | ||
| 47 | + 'foo../.bar.txt' | ||
| 48 | + >>> san('\\foo\\bar.txt') | ||
| 49 | + 'foo/bar.txt' | ||
| 50 | + >>> san('D:\\foo.txt') | ||
| 51 | + 'D/foo.txt' | ||
| 52 | + >>> san('\\\\server\\share\\file.txt') | ||
| 53 | + 'server/share/file.txt' | ||
| 54 | + >>> san('\\\\?\\GLOBALROOT\\Volume3') | ||
| 55 | + '?/GLOBALROOT/Volume3' | ||
| 56 | + >>> san('\\\\.\\PhysicalDrive1\\root') | ||
| 57 | + 'PhysicalDrive1/root' | ||
| 58 | + | ||
| 59 | + Retain any trailing slash. | ||
| 60 | + >>> san('abc/') | ||
| 61 | + 'abc/' | ||
| 62 | + | ||
| 63 | + Raises a ValueError if the result is empty. | ||
| 64 | + >>> san('../..') | ||
| 65 | + Traceback (most recent call last): | ||
| 66 | + ... | ||
| 67 | + ValueError: Empty filename | ||
| 68 | + """ | ||
| 69 | + | ||
| 70 | + def allowed(part): | ||
| 71 | + return part and part not in {'..', '.'} | ||
| 72 | + | ||
| 73 | + # Remove the drive letter. | ||
| 74 | + # Don't use ntpath.splitdrive, because that also strips UNC paths | ||
| 75 | + bare = re.sub('^([A-Z]):', r'\1', name, flags=re.IGNORECASE) | ||
| 76 | + clean = bare.replace('\\', '/') | ||
| 77 | + parts = clean.split('/') | ||
| 78 | + joined = '/'.join(filter(allowed, parts)) | ||
| 79 | + if not joined: | ||
| 80 | + raise ValueError("Empty filename") | ||
| 81 | + return joined + '/' * name.endswith('/') | ||
| 82 | + | ||
| 83 | + | ||
| 84 | class CompleteDirs(zipfile.ZipFile): | ||
| 85 | """ | ||
| 86 | A ZipFile subclass that ensures that implied directories | ||
| 87 | -- | ||
| 88 | 2.25.1 | ||
| 89 | |||
