From f2217df5b27599674729134487b9c0f3aae0b103 Mon Sep 17 00:00:00 2001 From: Wojciech Porczyk Date: Mon, 14 Jul 2025 10:28:48 +0200 Subject: [PATCH] tarfile: Make it possible to extract nested tarfiles in memory. FileSection.skip() (see below the diff) uses 2-argument readinto, so attempting to recursively extract archives throws an error. This commit adds optional second argument to fix this problem. After this commit, it is possible to extract nested archives in roughly this fashion: with open(path, 'rb') as file: tar_outer = tarfile.TarFile(fileobj=file) for ti_outer in tar_outer: tar_inner = tarfile.TarFile( fileobj=tar_outer.extractfile(ti_outer)) for ti_inner in tar_inner: ... Nested archives are used in some embedded contexts, for example Mender artifacts. Signed-off-by: Wojciech Porczyk --- python-stdlib/tarfile/tarfile/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python-stdlib/tarfile/tarfile/__init__.py b/python-stdlib/tarfile/tarfile/__init__.py index 4bb95af30..b56914106 100644 --- a/python-stdlib/tarfile/tarfile/__init__.py +++ b/python-stdlib/tarfile/tarfile/__init__.py @@ -41,11 +41,13 @@ def read(self, sz=65536): self.content_len -= sz return data - def readinto(self, buf): + def readinto(self, buf, size=None): if self.content_len == 0: return 0 if len(buf) > self.content_len: buf = memoryview(buf)[: self.content_len] + if size is not None and len(buf) > size: + buf = memoryview(buf)[:size] sz = self.f.readinto(buf) self.content_len -= sz return sz pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy