File tree 2 files changed +50
-0
lines changed
2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ try :
2
+ import zlib
3
+ except ImportError :
4
+ import uzlib as zlib
5
+ import uio as io
6
+
7
+
8
+ # gzip bitstream
9
+ buf = io .BytesIO (b'\x1f \x8b \x08 \x08 \x99 \x0c \xe5 W\x00 \x03 hello\x00 \xcb H\xcd \xc9 \xc9 \x07 \x00 \x86 \xa6 \x10 6\x05 \x00 \x00 \x00 ' )
10
+ inp = zlib .DecompIO (buf , 16 + 8 )
11
+ print (buf .seek (0 , 1 ))
12
+ print (inp .read (1 ))
13
+ print (buf .seek (0 , 1 ))
14
+ print (inp .read (2 ))
15
+ print (inp .read ())
16
+ print (buf .seek (0 , 1 ))
17
+ print (inp .read (1 ))
18
+ print (inp .read ())
19
+ print (buf .seek (0 , 1 ))
20
+
21
+ # broken header
22
+ buf = io .BytesIO (b'\x1f \x8c \x08 \x08 \x99 \x0c \xe5 W\x00 \x03 hello\x00 \xcb H\xcd \xc9 \xc9 \x07 \x00 \x86 \xa6 \x10 6\x05 \x00 \x00 \x00 ' )
23
+ try :
24
+ inp = zlib .DecompIO (buf , 16 + 8 )
25
+ except ValueError :
26
+ print ("ValueError" )
27
+
28
+ # broken crc32
29
+ buf = io .BytesIO (b'\x1f \x8b \x08 \x08 \x99 \x0c \xe5 W\x00 \x03 hello\x00 \xcb H\xcd \xc9 \xc9 \x07 \x00 \x86 \xa7 \x10 6\x05 \x00 \x00 \x00 ' )
30
+ inp = zlib .DecompIO (buf , 16 + 8 )
31
+ try :
32
+ inp .read (6 )
33
+ except OSError as e :
34
+ print (repr (e ))
35
+
36
+ # broken uncompressed size - not checked so far
37
+ #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')
38
+ #inp = zlib.DecompIO(buf, 16 + 8)
39
+ #inp.read(6)
Original file line number Diff line number Diff line change
1
+ 16
2
+ b'h'
3
+ 18
4
+ b'el'
5
+ b'lo'
6
+ 31
7
+ b''
8
+ b''
9
+ 31
10
+ ValueError
11
+ OSError(22,)
You can’t perform that action at this time.
0 commit comments