summaryrefslogtreecommitdiff
path: root/gnu/packages/patches/python-zipfile2-python-3.12-support.patch
blob: 7f7be331bfb652045d1840e7c19b09b128e76f23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
From 5ea38d6eaaa5c0d452b5dd73699486f79641b870 Mon Sep 17 00:00:00 2001
From: Ioannis Tziakos <mail@itziakos.gr>
Date: Sat, 17 Aug 2024 12:18:04 +0100
Subject: [PATCH] Fix LeanZipFile support for Python 3.12

---
 zipfile2/_lean_zipfile.py | 10 +++++++---
 zipfile2/common.py        |  3 +++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/zipfile2/_lean_zipfile.py b/zipfile2/_lean_zipfile.py
index 0a6e1c4..e9af3bd 100644
--- a/zipfile2/_lean_zipfile.py
+++ b/zipfile2/_lean_zipfile.py
@@ -62,9 +62,10 @@
         stringFileHeader,
         structCentralDir,
         structFileHeader,
+        crc32
     )
 
-from .common import TooManyFiles
+from .common import TooManyFiles, PY312
 
 _UTF8_EXTENSION_FLAG = 0x800
 
@@ -164,6 +165,7 @@ def get_zip_infos(self, *filenames):
             if centdir[_CD_SIGNATURE] != stringCentralDir:
                 raise BadZipFile("Bad magic number for central directory")
             filename = fp.read(centdir[_CD_FILENAME_LENGTH])
+            orig_filename_crc = crc32(filename)
             flags = centdir[5]
             if flags & _UTF8_EXTENSION_FLAG:
                 # UTF-8 file names extension
@@ -187,8 +189,10 @@ def get_zip_infos(self, *filenames):
             x._raw_time = t
             x.date_time = ((d >> 9) + 1980, (d >> 5) & 0xF, d & 0x1F,
                            t >> 11, (t >> 5) & 0x3F, (t & 0x1F) * 2)
-
-            x._decodeExtra()
+            if PY312:
+                x._decodeExtra(orig_filename_crc)
+            else:
+                x._decodeExtra()
             x.header_offset = x.header_offset + concat
 
             # update total bytes read from central directory
diff --git a/zipfile2/common.py b/zipfile2/common.py
index 7dbaea0..a25645a 100644
--- a/zipfile2/common.py
+++ b/zipfile2/common.py
@@ -1,5 +1,8 @@
 import zipfile
+import platform
 
+PYTHON_VERSION = tuple(map(int, platform.python_version_tuple()))
+PY312 = PYTHON_VERSION >= (3, 12, 0)
 
 class TooManyFiles(zipfile.BadZipfile):
     pass