New submission from Diego Argueta <diego.argu...@gmail.com>:

The Python documentation states that if the GzipFile can't determine a filename 
from `fileobj` it'll use an empty string and won't be included in the header. 
Unfortunately, this doesn't work for SpooledTemporaryFile which has a `name` 
attribute but doesn't set it initially. The result is a crash.

To reproduce

```
import gzip
import tempfile

with tempfile.SpooledTemporaryFile() as fd:
    with gzip.GzipFile(mode='wb', fileobj=fd) as gz:
        gz.write(b'asdf')
```

Result:
```
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/Users/diegoargueta/.pyenv/versions/2.7.14/lib/python2.7/gzip.py", line 
136, in __init__
    self._write_gzip_header()
  File "/Users/diegoargueta/.pyenv/versions/2.7.14/lib/python2.7/gzip.py", line 
170, in _write_gzip_header
    fname = os.path.basename(self.name)
  File "/Users/diegoargueta/.pyenv/versions/gds27/lib/python2.7/posixpath.py", 
line 114, in basename
    i = p.rfind('/') + 1
AttributeError: 'NoneType' object has no attribute 'rfind'
```

This doesn't happen on Python 3.6, where the null filename is handled properly. 
I've attached a patch file that fixed the issue for me.

----------
components: Library (Lib)
files: gzip_filename_fix.patch
keywords: patch
messages: 313512
nosy: da
priority: normal
severity: normal
status: open
title: GzipFile doesn't always ignore None as filename
type: crash
versions: Python 2.7
Added file: https://bugs.python.org/file47473/gzip_filename_fix.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33038>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to