2016-09-24 08:43:23 -04:00
|
|
|
try:
|
2023-08-22 11:15:46 -04:00
|
|
|
import zlib
|
|
|
|
import io
|
2017-02-14 17:56:22 -05:00
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
2017-06-10 13:14:16 -04:00
|
|
|
raise SystemExit
|
2016-09-24 08:43:23 -04:00
|
|
|
|
2023-08-22 11:15:46 -04:00
|
|
|
try:
|
|
|
|
zlib.decompIO
|
|
|
|
except AttributeError:
|
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
|
|
|
|
2016-09-24 08:43:23 -04:00
|
|
|
|
|
|
|
# gzip bitstream
|
2021-03-15 09:57:36 -04:00
|
|
|
buf = io.BytesIO(
|
|
|
|
b"\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
|
|
|
|
)
|
2016-09-24 08:43:23 -04:00
|
|
|
inp = zlib.DecompIO(buf, 16 + 8)
|
|
|
|
print(buf.seek(0, 1))
|
|
|
|
print(inp.read(1))
|
|
|
|
print(buf.seek(0, 1))
|
|
|
|
print(inp.read(2))
|
|
|
|
print(inp.read())
|
|
|
|
print(buf.seek(0, 1))
|
|
|
|
print(inp.read(1))
|
|
|
|
print(inp.read())
|
|
|
|
print(buf.seek(0, 1))
|
|
|
|
|
2017-03-14 04:00:56 -04:00
|
|
|
# Check FHCRC field
|
2021-03-15 09:57:36 -04:00
|
|
|
buf = io.BytesIO(
|
|
|
|
b"\x1f\x8b\x08\x02\x99\x0c\xe5W\x00\x03\x00\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
|
|
|
|
)
|
2017-03-14 04:00:56 -04:00
|
|
|
inp = zlib.DecompIO(buf, 16 + 8)
|
|
|
|
print(inp.read())
|
|
|
|
|
|
|
|
# Check FEXTRA field
|
2021-03-15 09:57:36 -04:00
|
|
|
buf = io.BytesIO(
|
|
|
|
b"\x1f\x8b\x08\x04\x99\x0c\xe5W\x00\x03\x01\x00X\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
|
|
|
|
)
|
2017-03-14 04:00:56 -04:00
|
|
|
inp = zlib.DecompIO(buf, 16 + 8)
|
|
|
|
print(inp.read())
|
|
|
|
|
2016-09-24 08:43:23 -04:00
|
|
|
# broken header
|
2021-03-15 09:57:36 -04:00
|
|
|
buf = io.BytesIO(
|
|
|
|
b"\x1f\x8c\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
|
|
|
|
)
|
2016-09-24 08:43:23 -04:00
|
|
|
try:
|
|
|
|
inp = zlib.DecompIO(buf, 16 + 8)
|
|
|
|
except ValueError:
|
|
|
|
print("ValueError")
|
|
|
|
|
|
|
|
# broken crc32
|
2021-03-15 09:57:36 -04:00
|
|
|
buf = io.BytesIO(
|
|
|
|
b"\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa7\x106\x05\x00\x00\x00"
|
|
|
|
)
|
2016-09-24 08:43:23 -04:00
|
|
|
inp = zlib.DecompIO(buf, 16 + 8)
|
|
|
|
try:
|
|
|
|
inp.read(6)
|
|
|
|
except OSError as e:
|
|
|
|
print(repr(e))
|
|
|
|
|
|
|
|
# broken uncompressed size - not checked so far
|
2021-03-15 09:57:36 -04:00
|
|
|
# buf = io.BytesIO(b'\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x06\x00\x00\x00')
|
|
|
|
# inp = zlib.DecompIO(buf, 16 + 8)
|
|
|
|
# inp.read(6)
|