Skip to content

Commit

Permalink
fix(handler): improve tar handler to support sparse archives.
Browse files Browse the repository at this point in the history
  • Loading branch information
qkaiser committed Dec 1, 2023
1 parent d086d25 commit 623b4b7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions unblob/handlers/archive/_safe_tarfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import os
import tarfile
from pathlib import Path
from tarfile import (
GNUTYPE_LONGLINK,
GNUTYPE_LONGNAME,
GNUTYPE_SPARSE,
SOLARIS_XHDTYPE,
XGLTYPE,
XHDTYPE,
)

from structlog import get_logger

Expand Down Expand Up @@ -143,3 +151,19 @@ def record_problem(self, tarinfo, problem, resolution):
resolution=resolution,
)
)


def _proc_member(self, tarfile):
if self.type in (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK):
return self._proc_gnulong(tarfile)
if self.type == GNUTYPE_SPARSE:
orig_size = self.size
self = self._proc_sparse(tarfile)
self.size = orig_size
return self
if self.type in (XHDTYPE, XGLTYPE, SOLARIS_XHDTYPE):
return self._proc_pax(tarfile)
return self._proc_builtin(tarfile)


tarfile.TarInfo._proc_member = _proc_member # type: ignore # noqa: SLF001

0 comments on commit 623b4b7

Please sign in to comment.