File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,21 @@ import gzip
8
8
import os
9
9
import contextlib
10
10
11
+ # monkey-patch Python 3.8 and older to fix wrong TAR header handling
12
+ # see https://github.com/bitcoin/bitcoin/pull/24534
13
+ # and https://github.com/python/cpython/pull/18080 for more info
14
+ if sys .version_info < (3 , 9 ):
15
+ _old_create_header = tarfile .TarInfo ._create_header
16
+ def _create_header (info , format , encoding , errors ):
17
+ buf = _old_create_header (info , format , encoding , errors )
18
+ # replace devmajor/devminor with binary zeroes
19
+ buf = buf [:329 ] + bytes (16 ) + buf [345 :]
20
+ # recompute checksum
21
+ chksum = tarfile .calc_chksums (buf )[0 ]
22
+ buf = buf [:- 364 ] + bytes ("%06o\0 " % chksum , "ascii" ) + buf [- 357 :]
23
+ return buf
24
+ tarfile .TarInfo ._create_header = staticmethod (_create_header )
25
+
11
26
@contextlib .contextmanager
12
27
def cd (path ):
13
28
"""Context manager that restores PWD even if an exception was raised."""
You can’t perform that action at this time.
0 commit comments