New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tarfiles: AttributeError: '_Stream' object has no attribute 'exception'
while trying to open tgz file
#107396
Comments
Looks reasonable. Will you open a PR? |
Sure |
In the stack call of: _init_read_gz() ``` _read, tarfile.py:548 read, tarfile.py:526 _init_read_gz, tarfile.py:491 ``` a try;except exists that uses `self.exception`, so it needs to be set before calling _init_read_gz().
In the stack call of: _init_read_gz() ``` _read, tarfile.py:548 read, tarfile.py:526 _init_read_gz, tarfile.py:491 ``` a try;except exists that uses `self.exception`, so it needs to be set before calling _init_read_gz(). closes: python#107396
In the stack call of: _init_read_gz() ``` _read, tarfile.py:548 read, tarfile.py:526 _init_read_gz, tarfile.py:491 ``` a try;except exists that uses `self.exception`, so it needs to be set before calling _init_read_gz(). closes: python#107396
In the stack call of: _init_read_gz() ``` _read, tarfile.py:548 read, tarfile.py:526 _init_read_gz, tarfile.py:491 ``` a try;except exists that uses `self.exception`, so it needs to be set before calling _init_read_gz(). closes: python#107396
Hello, |
Maybe that one will explain better the sequence where this failure can happen. My interpretation is that gzip supports backwards skipping and it appears to be rarely used. If I open a tgz with |
Oh, I see! with open('hm.tar.gz', 'rb') as f:
f = io.BytesIO(
b'\x1f\x8b' # header
+ b'\x08' # compression method
+ b'\x04' # flags
+ b'\0\0\0\0\0\0' # padding?
+ b'\0\x01' # size
+ bytes(5) # corrupt data (zeros)
)
tarfile.open(fileobj=f, mode='r|gz') If you can add it as a test using |
OK. I will. |
In the stack call of: _init_read_gz() ``` _read, tarfile.py:548 read, tarfile.py:526 _init_read_gz, tarfile.py:491 ``` a try;except exists that uses `self.exception`, so it needs to be set before calling _init_read_gz(). closes: python#107396
…7485) In the stack call of: _init_read_gz() ``` _read, tarfile.py:548 read, tarfile.py:526 _init_read_gz, tarfile.py:491 ``` a try;except exists that uses `self.exception`, so it needs to be set before calling _init_read_gz().
…ythonGH-107485) In the stack call of: _init_read_gz() ``` _read, tarfile.py:548 read, tarfile.py:526 _init_read_gz, tarfile.py:491 ``` a try;except exists that uses `self.exception`, so it needs to be set before calling _init_read_gz(). (cherry picked from commit 37135d2) Co-authored-by: balmeida-nokia <83089745+balmeida-nokia@users.noreply.github.com>
…ythonGH-107485) In the stack call of: _init_read_gz() ``` _read, tarfile.py:548 read, tarfile.py:526 _init_read_gz, tarfile.py:491 ``` a try;except exists that uses `self.exception`, so it needs to be set before calling _init_read_gz(). (cherry picked from commit 37135d2) Co-authored-by: balmeida-nokia <83089745+balmeida-nokia@users.noreply.github.com>
…GH-107485) (#108207) gh-107396: tarfiles: set self.exception before _init_read_gz() (GH-107485) In the stack call of: _init_read_gz() ``` _read, tarfile.py:548 read, tarfile.py:526 _init_read_gz, tarfile.py:491 ``` a try;except exists that uses `self.exception`, so it needs to be set before calling _init_read_gz(). (cherry picked from commit 37135d2) Co-authored-by: balmeida-nokia <83089745+balmeida-nokia@users.noreply.github.com>
…GH-107485) (GH-108208) gh-107396: tarfiles: set self.exception before _init_read_gz() (GH-107485) In the stack call of: _init_read_gz() ``` _read, tarfile.py:548 read, tarfile.py:526 _init_read_gz, tarfile.py:491 ``` a try;except exists that uses `self.exception`, so it needs to be set before calling _init_read_gz(). (cherry picked from commit 37135d2) Co-authored-by: balmeida-nokia <83089745+balmeida-nokia@users.noreply.github.com>
Bug report
If a tar file appears to be a
tar.gz
file, it can fail in this block oftarfile.py
at:
before
self.exception
is set.Because around:
This:
self._init_read_gz()
is called before
self.exception = zlib.error
Stack trace:
In my case,
buf = self.cmp.decompress(buf)
failed to execute but that's a separate issue that may or may not be a bugYour environment
Linked PRs
The text was updated successfully, but these errors were encountered: