-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Closed as not planned
Closed as not planned
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
import array
import gzip
# Create a one-element, uint16 array
a=array.array('H', [1])
# The memoryview has len(1) but itemsize=2 and nbytes=2
x=memoryview(a)
d=gzip.compress(x)
gzip.decompress(d)Or one-liner
python3.12 -c "import array; a=array.array('H', [1]); x=memoryview(a); import gzip; d=gzip.compress(x); gzip.decompress(d)"prints
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.12/gzip.py", line 657, in decompress
raise BadGzipFile("Incorrect length of data produced")
gzip.BadGzipFile: Incorrect length of data produced
This works in Python 3.13.0.
The gzip.py is creating the CRC trailer by calling len(data), which gives the number of elements for a memoryview, not the number of bytes. So the trailer is incorrect, and then it fails to decompress.
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error