Skip to content

tarfiles can't open tgz files with gzip features like FEXTRA & FCOMMENT when mode='r|*' #107398

@balmeida-nokia

Description

@balmeida-nokia

Bug report

If a tar file is streamed from network and read into tarfiles as:
with tarfile.open(mode='r|*', fileobj=stream) as tfile

however, if mode is r:*. I.e. with tarfile.open(mode='r:*', fileobj=stream) as tfile
this problem disappears.

reading fails within:

        while c < size:
            # Skip underlying buffer to avoid unaligned double buffering.
            if self.buf:
                buf = self.buf
                self.buf = b""
            else:
                buf = self.fileobj.read(self.bufsize)
                if not buf:
                    break
            try:
                buf = self.cmp.decompress(buf)
            except self.exception as e:
                raise ReadError("invalid compressed data") from e
            t.append(buf)
            c += len(buf)

at:

buf = self.cmp.decompress(buf)

with exception:

zlib.error: Error -3 while decompressing data: invalid distance too far back

Stack trace:

_read, tarfile.py:548
read, tarfile.py:526
_init_read_gz, tarfile.py:491
__init__, tarfile.py:375
open, tarfile.py:1827
<module>, test.py:2

This appears to happen with tgz files created by the helm charts tool but I'm having a hard time reproducing without having any NDA data or metadata.

Your environment

  • CPython versions tested on: 3.11.4
  • Operating system and architecture: Windows 10 21H2

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions