diff --git a/backport-CVE-2025-8291.patch b/backport-CVE-2025-8291.patch new file mode 100644 index 0000000000000000000000000000000000000000..84654c12b601bd5527ba904a30dbd35a6bcc20ad --- /dev/null +++ b/backport-CVE-2025-8291.patch @@ -0,0 +1,307 @@ +From d8a71bec60ca197650bd93196a804083ba529b53 Mon Sep 17 00:00:00 2001 +From: Serhiy Storchaka +Date: Tue, 7 Oct 2025 20:55:44 +0300 +Subject: [PATCH] [3.13] gh-139700: Check consistency of the zip64 end of + central directory record (GH-139702) (GH-139708) (cherry picked from commit + 333d4a6f4967d3ace91492a39ededbcf3faa76a6) + +Co-authored-by: Serhiy Storchaka +Support records with "zip64 extensible data" if there are no bytes +prepended to the ZIP file. +(cherry picked from commit 162997bb70e067668c039700141770687bc8f267) +--- + 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 5809b2c00060a6..fbf3f8649ca5fe 100644 +--- a/Lib/test/test_zipfile.py ++++ b/Lib/test/test_zipfile.py +@@ -859,6 +859,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. + +@@ -912,6 +914,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 +@@ -250,6 +266,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 + + +@@ -283,7 +300,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" +@@ -307,8 +324,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 +@@ -1341,9 +1357,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 +@@ -1922,7 +1935,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 00000000000000..a8e7a1f1878c6b +--- /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. diff --git a/python3.spec b/python3.spec index dc082e55c253cfa1622e36dcc27f604d871ae939..7cc8fe03faeb34634ed1b3f7aede31c389df0e03 100644 --- a/python3.spec +++ b/python3.spec @@ -3,7 +3,7 @@ Summary: Interpreter of the Python3 programming language URL: https://www.python.org/ Version: 3.7.9 -Release: 44 +Release: 45 License: Python-2.0 %global branchversion 3.7 @@ -175,6 +175,7 @@ Patch6063: backport-0001-CVE-2023-40217.patch Patch6064: backport-0002-CVE-2023-40217.patch Patch6065: backport-0003-CVE-2023-40217.patch Patch6066: backport-CVE-2025-1795.patch +Patch6067: backport-CVE-2025-8291.patch patch9000: Don-t-override-PYTHONPATH-which-is-already-set.patch patch9001: add-the-sm3-method-for-obtaining-the-salt-value.patch @@ -352,6 +353,7 @@ rm Lib/ensurepip/_bundled/*.whl %patch6064 -p1 %patch6065 -p1 %patch6066 -p1 +%patch6067 -p1 %patch9000 -p1 %patch9001 -p1 @@ -974,6 +976,9 @@ export BEP_GTDLIST="$BEP_GTDLIST_TMP" %{_mandir}/*/* %changelog +* Wed Oct 8 2025 lizhipeng - 3.7.9-45 +- fix CVE-2025-8291 + * Mon Sep 01 2025 lipengyu - 3.7.9-44 - Type:CVE - CVE:CVE-2025-1795