diff --git a/Lib/gzip.py b/Lib/gzip.py index 971063aa24f871..d02f62d42346eb 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -484,40 +484,63 @@ def _read_exact(fp, n): return data +def _read_until_null(fp): + '''Read until the first encountered null byte in fp''' + result = io.BytesIO() + while True: + s = fp.read(1) + if not s: + raise EOFError("Compressed file ended before the " + "end-of-stream marker was reached") + result.write(s) + if s == b'\000': + break + return result.getvalue() + + def _read_gzip_header(fp): '''Read a gzip header from `fp` and progress to the end of the header. Returns last mtime if header was present or None otherwise. ''' magic = fp.read(2) - if magic == b'': + if not magic: return None if magic != b'\037\213': raise BadGzipFile('Not a gzipped file (%r)' % magic) - - (method, flag, last_mtime) = struct.unpack("