File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -302,7 +302,8 @@ def _read_gzip_header(self):
302302
303303 if flag & FEXTRA :
304304 # Read & discard the extra field, if present
305- self ._read_exact (struct .unpack ("<H" , self ._read_exact (2 )))
305+ extra_len , = struct .unpack ("<H" , self ._read_exact (2 ))
306+ self ._read_exact (extra_len )
306307 if flag & FNAME :
307308 # Read and discard a null-terminated string containing the filename
308309 while True :
Original file line number Diff line number Diff line change @@ -403,6 +403,13 @@ def test_read_truncated(self):
403403 with gzip .GzipFile (fileobj = io .BytesIO (truncated [:i ])) as f :
404404 self .assertRaises (EOFError , f .read , 1 )
405405
406+ def test_read_with_extra (self ):
407+ # Gzip data with an extra field
408+ gzdata = (b'\x1f \x8b \x08 \x04 \xb2 \x17 cQ\x02 \xff '
409+ b'\x05 \x00 Extra'
410+ b'\x0b I-.\x01 \x00 2\xd1 Mx\x04 \x00 \x00 \x00 ' )
411+ with gzip .GzipFile (fileobj = io .BytesIO (gzdata )) as f :
412+ self .assertEqual (f .read (), b'Test' )
406413
407414class TestOpen (BaseTest ):
408415 def test_binary_modes (self ):
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ Core and Builtins
3030Library
3131-------
3232
33+ - Issue #17666: Fix reading gzip files with an extra field.
34+
3335- Issue #16475: Support object instancing, recursion and interned strings
3436 in marshal
3537
You can’t perform that action at this time.
0 commit comments