Comment 3 for bug 1947800

Revision history for this message
Benjamin Drung (bdrung) wrote (last edit ):

Bug analysis
============

whoopsie-upload-all reads the *.crash files (to upload them):

```
r = apport.Report()
with open(report, 'rb') as f:
    r.load(f, binary='compressed')
```

ProblemReport.load reads the encoded data and keeps in compressed:

```python
block = base64.b64decode(line)
if value.gzipvalue == b'' and not block.startswith(b'\037\213\010'):
    value.legacy_zlib = True
value.gzipvalue += block
```

Derived from the code path, `legacy_zlib` is set to `False` in this case. Then `Report.gdb_command` tries to decompress the CoreDump field and write it into a temporary file. The relevant part from `problem_report.py` from apport 2.20.11-0ubuntu71 (line 73):

```python
gz = gzip.GzipFile(fileobj=BytesIO(self.gzipvalue))
while True:
    block = gz.read(1048576)
    if not block:
        break
    file.write(block)
```

So the only two reasons that I can see why decompressing the byte object `gzipvalue`:
1. The content of the CoreDump field in the .crash file is malformed.
2. `legacy_zlib` is set to `False` instead of `True`.

Reproduction
============

I tried to reproduce the `zlib.error` by feeding it with wrong data:

```
In [1]: import gzip

In [2]: from io import BytesIO

In [3]: gzip.GzipFile(fileobj=BytesIO(None)).read(1048576)
Out[3]: b''

In [4]: gzip.GzipFile(fileobj=BytesIO(b"")).read(1048576)
Out[4]: b''

In [5]: gzip.GzipFile(fileobj=BytesIO(b"bogus")).read(1048576)
[...]
BadGzipFile: Not a gzipped file (b'bo')
```