Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

tarfiles:AttributeError: '_Stream' object has no attribute 'exception' while trying to open tgz file #107396

Closed
Labels
3.11only security fixes3.12only security fixes3.13bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@balmeida-nokia

Description

@balmeida-nokia

Bug report

If a tar file appears to be atar.gz file, it can fail in this block oftarfile.py

        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)

beforeself.exception is set.
Because around:

            if comptype == "gz":                try:                    import zlib                except ImportError:                    raise CompressionError("zlib module is not available") from None                self.zlib = zlib                self.crc = zlib.crc32(b"")                if mode == "r":                    self._init_read_gz()                    self.exception = zlib.error                else:                    self._init_write_gz()

This:self._init_read_gz()
is called beforeself.exception = zlib.error

Stack trace:

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

In my case,buf = self.cmp.decompress(buf) failed to execute but that's a separate issue that may or may not be a bug

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

    3.11only security fixes3.12only security fixes3.13bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp