From 3a2c7d3c512d036a0cc70b73ed6bf26a55699b5e Mon Sep 17 00:00:00 2001 From: abushwang Date: Wed, 22 Oct 2025 10:09:04 +0800 Subject: [PATCH] fix CVE-2025-8291 Signed-off-by: abushwang --- ...heck-consistency-of-the-zip64-end-of.patch | 313 ++++++++++++++++++ python3.11.spec | 8 +- 2 files changed, 320 insertions(+), 1 deletion(-) create mode 100644 CVE-2025-8291-3.11-gh-139700-Check-consistency-of-the-zip64-end-of.patch diff --git a/CVE-2025-8291-3.11-gh-139700-Check-consistency-of-the-zip64-end-of.patch b/CVE-2025-8291-3.11-gh-139700-Check-consistency-of-the-zip64-end-of.patch new file mode 100644 index 0000000..1510bf6 --- /dev/null +++ b/CVE-2025-8291-3.11-gh-139700-Check-consistency-of-the-zip64-end-of.patch @@ -0,0 +1,313 @@ +From 1d29afb0d6218aa8fb5e1e4a6133a4778d89bb46 Mon Sep 17 00:00:00 2001 +From: "Miss Islington (bot)" + <31488909+miss-islington@users.noreply.github.com> +Date: Wed, 8 Oct 2025 13:46:45 +0200 +Subject: [PATCH] [3.11] gh-139700: Check consistency of the zip64 end of + central directory record (GH-139702) (GH-139708) (GH-139713) + +(cherry picked from commit 333d4a6f4967d3ace91492a39ededbcf3faa76a6) + +Support records with "zip64 extensible data" if there are no bytes +prepended to the ZIP file. +(cherry picked from commit 162997bb70e067668c039700141770687bc8f267) + +Co-authored-by: Serhiy Storchaka +--- + Lib/test/test_zipfile.py | 82 ++++++++++++++++++- + Lib/zipfile.py | 51 +++++++----- + ...-10-07-19-31-34.gh-issue-139700.vNHU1O.rst | 3 + + 3 files changed, 113 insertions(+), 23 deletions(-) + create mode 100644 Misc/NEWS.d/next/Security/2025-10-07-19-31-34.gh-issue-139700.vNHU1O.rst + +diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py +index 52831a7bd7c..a0bca62ab88 100644 +--- a/Lib/test/test_zipfile.py ++++ b/Lib/test/test_zipfile.py +@@ -887,6 +887,8 @@ def make_zip64_file( + self, file_size_64_set=False, file_size_extra=False, + compress_size_64_set=False, compress_size_extra=False, + header_offset_64_set=False, header_offset_extra=False, ++ extensible_data=b'', ++ end_of_central_dir_size=None, offset_to_end_of_central_dir=None, + ): + """Generate bytes sequence for a zip with (incomplete) zip64 data. + +@@ -940,6 +942,12 @@ def make_zip64_file( + + central_dir_size = struct.pack(' 1: + raise BadZipFile("zipfiles that span multiple disks are not supported") + +- # Assume no 'zip64 extensible data' +- fpin.seek(offset - sizeEndCentDir64Locator - sizeEndCentDir64, 2) ++ offset -= sizeEndCentDir64 ++ if reloff > offset: ++ raise BadZipFile("Corrupt zip64 end of central directory locator") ++ # First, check the assumption that there is no prepended data. ++ fpin.seek(reloff) ++ extrasz = offset - reloff + data = fpin.read(sizeEndCentDir64) + if len(data) != sizeEndCentDir64: +- return endrec ++ raise OSError("Unknown I/O error") ++ if not data.startswith(stringEndArchive64) and reloff != offset: ++ # Since we already have seen the Zip64 EOCD Locator, it's ++ # possible we got here because there is prepended data. ++ # Assume no 'zip64 extensible data' ++ fpin.seek(offset) ++ extrasz = 0 ++ data = fpin.read(sizeEndCentDir64) ++ if len(data) != sizeEndCentDir64: ++ raise OSError("Unknown I/O error") ++ if not data.startswith(stringEndArchive64): ++ raise BadZipFile("Zip64 end of central directory record not found") ++ + sig, sz, create_version, read_version, disk_num, disk_dir, \ + dircount, dircount2, dirsize, diroffset = \ + struct.unpack(structEndArchive64, data) +- if sig != stringEndArchive64: +- return endrec ++ if (diroffset + dirsize != reloff or ++ sz + 12 != sizeEndCentDir64 + extrasz): ++ raise BadZipFile("Corrupt zip64 end of central directory record") + + # Update the original endrec using data from the ZIP64 record + endrec[_ECD_SIGNATURE] = sig +@@ -280,6 +296,7 @@ def _EndRecData64(fpin, offset, endrec): + endrec[_ECD_ENTRIES_TOTAL] = dircount2 + endrec[_ECD_SIZE] = dirsize + endrec[_ECD_OFFSET] = diroffset ++ endrec[_ECD_LOCATION] = offset - extrasz + return endrec + + +@@ -313,7 +330,7 @@ def _EndRecData(fpin): + endrec.append(filesize - sizeEndCentDir) + + # Try to read the "Zip64 end of central directory" structure +- return _EndRecData64(fpin, -sizeEndCentDir, endrec) ++ return _EndRecData64(fpin, filesize - sizeEndCentDir, endrec) + + # Either this is not a ZIP file, or it is a ZIP file with an archive + # comment. Search the end of the file for the "end of central directory" +@@ -337,8 +354,7 @@ def _EndRecData(fpin): + endrec.append(maxCommentStart + start) + + # Try to read the "Zip64 end of central directory" structure +- return _EndRecData64(fpin, maxCommentStart + start - filesize, +- endrec) ++ return _EndRecData64(fpin, maxCommentStart + start, endrec) + + # Unable to find a valid end of central directory structure + return None +@@ -1386,9 +1402,6 @@ def _RealGetContents(self): + + # "concat" is zero, unless zip was concatenated to another file + concat = endrec[_ECD_LOCATION] - size_cd - offset_cd +- if endrec[_ECD_SIGNATURE] == stringEndArchive64: +- # If Zip64 extension structures are present, account for them +- concat -= (sizeEndCentDir64 + sizeEndCentDir64Locator) + + if self.debug > 2: + inferred = concat + offset_cd +@@ -1989,7 +2002,7 @@ def _write_end_record(self): + " would require ZIP64 extensions") + zip64endrec = struct.pack( + structEndArchive64, stringEndArchive64, +- 44, 45, 45, 0, 0, centDirCount, centDirCount, ++ sizeEndCentDir64 - 12, 45, 45, 0, 0, centDirCount, centDirCount, + centDirSize, centDirOffset) + self.fp.write(zip64endrec) + +diff --git a/Misc/NEWS.d/next/Security/2025-10-07-19-31-34.gh-issue-139700.vNHU1O.rst b/Misc/NEWS.d/next/Security/2025-10-07-19-31-34.gh-issue-139700.vNHU1O.rst +new file mode 100644 +index 00000000000..a8e7a1f1878 +--- /dev/null ++++ b/Misc/NEWS.d/next/Security/2025-10-07-19-31-34.gh-issue-139700.vNHU1O.rst +@@ -0,0 +1,3 @@ ++Check consistency of the zip64 end of central directory record. Support ++records with "zip64 extensible data" if there are no bytes prepended to the ++ZIP file. +-- +2.39.3 + diff --git a/python3.11.spec b/python3.11.spec index 62c70ea..4f684bb 100644 --- a/python3.11.spec +++ b/python3.11.spec @@ -64,7 +64,7 @@ Summary: Version %{pybasever} of the Python interpreter Name: python%{pybasever} Version: %{src_version} -Release: 23%{?dist} +Release: 24%{?dist} License: Python-2.0.1 URL: https://www.python.org/ @@ -115,6 +115,7 @@ Patch0036: https://github.com/python/cpython/commit/5f90abaa786f994db3907fc31e2e Patch0037: https://github.com/python/cpython/commit/c5655aa6ad120d2ed7f255bebd6e8b71a9c07dde.patch # https://github.com/python/cpython/commit/bc4a703a934a59657ecd018320ef990bc5542803 Patch0038: https://github.com/python/cpython/commit/bc4a703a934a59657ecd018320ef990bc5542803-mod.patch +Patch0039: CVE-2025-8291-3.11-gh-139700-Check-consistency-of-the-zip64-end-of.patch Patch3000: 00001-rpath.patch Patch3001: 00251-change-user-install-location.patch @@ -1147,6 +1148,11 @@ LD_LIBRARY_PATH=$(pwd)/normal $(pwd)/normal/python -m test.regrtest \ %endif %changelog +* Wed Oct 22 2025 Shuo Wang - 3.11.6-24 +- fix CVE-2025-8291 +- gh-139700: Check consistency of the zip64 end of +- central directory record (GH-139702) (GH-139708) (GH-139713) + * Wed Sep 24 2025 Tracker Robot - 3.11.6-23 - [Type] security - [DESC] Apply patches from rpm-tracker -- Gitee