From cc09ac408409adbe0e41022bdb219067d53521ee Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Sat, 2 Nov 2024 02:01:48 +0800 Subject: [PATCH 1/5] gh-107398: Fix tarfile stream mode exception when process the file with extra header data --- Lib/tarfile.py | 18 ++++++++++-------- Lib/test/test_tarfile.py | 6 +++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index a0fab46b24e249..75de0e3a1d063a 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -480,25 +480,27 @@ def _init_read_gz(self): # taken from gzip.GzipFile with some alterations if self.__read(2) != b"\037\213": raise ReadError("not a gzip file") - if self.__read(1) != b"\010": + (method, flag, _) = struct.unpack(" Date: Sat, 2 Nov 2024 02:02:38 +0800 Subject: [PATCH 2/5] add news --- .../next/Library/2024-11-02-02-02-31.gh-issue-107398.uUtA6Q.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2024-11-02-02-02-31.gh-issue-107398.uUtA6Q.rst diff --git a/Misc/NEWS.d/next/Library/2024-11-02-02-02-31.gh-issue-107398.uUtA6Q.rst b/Misc/NEWS.d/next/Library/2024-11-02-02-02-31.gh-issue-107398.uUtA6Q.rst new file mode 100644 index 00000000000000..ec3502e8b5facd --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-11-02-02-02-31.gh-issue-107398.uUtA6Q.rst @@ -0,0 +1,2 @@ +Fix tarfile stream mode exception when process the file with extra header +data. From db8e216d0f025379c446dd46ff031a10259cc2ca Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Sat, 2 Nov 2024 02:03:47 +0800 Subject: [PATCH 3/5] add test file --- .../tgz_with_comment_extra_data_in_header.tgz | Bin 0 -> 4183 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Lib/test/archivetestdata/tgz_with_comment_extra_data_in_header.tgz diff --git a/Lib/test/archivetestdata/tgz_with_comment_extra_data_in_header.tgz b/Lib/test/archivetestdata/tgz_with_comment_extra_data_in_header.tgz new file mode 100644 index 0000000000000000000000000000000000000000..b3d5ca05c1f94d8a5960de1f1ef3c10df358861e GIT binary patch literal 4183 zcmV-d5UB4TiwG0|00000|0w_~VMtOiV@ORlOnEsqVl!4SWK%V1T2nbTPgYhoO;>Dc zVQyr3R8em|NM&qo0PH+#ZyPz1^SOUTo$N&>xpYhNGiV?+kLF?fn3~`yyan%atbb zhu)oWwHNmnX(Xc`Q7S5U46~hpWLf#OAN3ESUXY?nB+az#JA!{An?hpF2#kb;|ILRe zIcih^CsT}J;Xnm?o?#3m%NR|F0Tav$6uqb)^@4BBga72VDE~9Ua#Z)J0M^TYzqi{z zY{~zAuitx=|A%N>@CrvHXBynTTcKV!6j87RA0|`*RY2gEqqlFuk&siOHKtGuc!dcg z5@ALpB}0Y^w16Q(MwG%7DAxk!BA1|XnlYkLML_}gf-(jQHRuU~M5`*y*F@x8!&FEF z${k87I3$D{$Rm;S6ecK*-qAW!akqP3Dx`>tZYmPhO$1Lc)2e$R0wOv{Y#!#wm zg{~X;&&LLB4E>Tmg<4tK%tS&tN}y9R#(N{JgsZw1u<8c(e;k0}hfq`tIgf#lDZdN= z+H_?(V~`0(leyhO2P6u>J{i~tF`SG}g&s&$$h8IXZiZ6Q6de$^Bu&O}F%b$O^+$vH zwOg%UnFs@2lW`24PEb1_2E7@sFp*}lw!=_C`4|ZISVmGzfj}ndjA*Q_@vbb@M4elH zj_5d-7-k|3OYU|J9igQl^r%CLW2&^AdyWrs#?CD1Du!Qwt1V0m5T0K(ei*YCS>snQ z(=ud~Gq%tfZ24VF?81gQWvK#@YtJw_qX_~@?)TU$Oma!}yz3E!9)aoxzURnw#P&>_ zWth+rMFkfV)Dx6I7D!VQk+akglSm{Q(*XRZ7_`jM0y@gIFq9{RF|(~^B7w68$|nkr z1}A22id<8|)c*tk#LRRuSV7}lXv+t?6C_Q|za@M#^Q*BjTwQy4LAzHVMoYP^1>_1N zJN9G*TxhG12v7aW>=B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;=JtVahSNZmYo9erdt9L4lTrY`1t=JV^L{M~{KfZ8o z)!5=iik9>3XVr@ETnimdwe(1RRx1=z6&0IF)%T^Exba2i3~yXRgSg^#5QE8<_$`oV z3r$LLTQ7&KDl)9r?aJ4iWrNMxZjXysO4=i;S52y2ZO(6S&$S^*&XK2aD^O5-1FP9? zCsEsrAqZcZzt9W7^XU+!1-^ZAIAe*C{j26c{*&7}`(JGSpKSko2fg<1KOFY=AAkSh zL0aSYUkX$1bKBpCDKCtyE>-KwiqBdQH}r2H-58p6F7%*!UCArSC6U@jIJlW6xBPV3}fqtfngmk~8d$!|s8OpcZ5ybUkbyx(HsO0;ih7dh)woT2=7@*kNlI_5&+J>j@X{`Ys= z`JcVRgGc}WLE07!h}J0Gj}5tPhl>gNAE%;x3>itz-H(YCKdO>v?&nn01Q~-d6GK-g zMfvzSNMuCQ8QOSAt)K8T*aD7Y_lD_@nZyyj#MBw+|9Tq1JI>}HxSeT8f()hoZHOp{ zUY&h9(?Vjf1-@MQ Date: Sat, 2 Nov 2024 20:28:51 +0800 Subject: [PATCH 4/5] Update Lib/test/test_tarfile.py Co-authored-by: Kirill Podoprigora --- Lib/test/test_tarfile.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 9a271cdb598e80..eadf83fecdc914 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -859,6 +859,8 @@ def test_read_through(self): "TarFile.extractfile() failed") if not buf: break + + @unittest.skipIf(zlib is None, "requires zlib") def test_read_with_extra_header(self): with tarfile.open(tgzname_with_comment_extra_data_in_header, mode="r|*") as _: From 3bc23ceea1abfbed5dc445db6aef9ad74761d9ea Mon Sep 17 00:00:00 2001 From: Nadeshiko Manju Date: Sat, 2 Nov 2024 20:28:59 +0800 Subject: [PATCH 5/5] Update Misc/NEWS.d/next/Library/2024-11-02-02-02-31.gh-issue-107398.uUtA6Q.rst Co-authored-by: Kirill Podoprigora --- .../next/Library/2024-11-02-02-02-31.gh-issue-107398.uUtA6Q.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-11-02-02-02-31.gh-issue-107398.uUtA6Q.rst b/Misc/NEWS.d/next/Library/2024-11-02-02-02-31.gh-issue-107398.uUtA6Q.rst index ec3502e8b5facd..728784cb42c5c1 100644 --- a/Misc/NEWS.d/next/Library/2024-11-02-02-02-31.gh-issue-107398.uUtA6Q.rst +++ b/Misc/NEWS.d/next/Library/2024-11-02-02-02-31.gh-issue-107398.uUtA6Q.rst @@ -1,2 +1,2 @@ -Fix tarfile stream mode exception when process the file with extra header +Fix :mod:`tarfile` stream mode exception when process the file with extra header. data.