Skip to content

Commit 7272be7

Browse files
committed
fix jpeg parser
1 parent 54889a1 commit 7272be7

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

fixtures/sample600x450.jpg

87.9 KB
Loading

imgspy.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,17 @@ def probe(stream):
8383
w, h = struct.unpack('<HH', chunk[6:10])
8484
return {'type': 'gif', 'width': w, 'height': h}
8585
elif chunk.startswith(b'\xff\xd8'):
86-
start = 0
86+
start = 2
8787
data = chunk
8888
while True:
89-
chunk = stream.read(10)
90-
if not chunk:
89+
if data[start:start+1] != b'\xff':
9190
return
92-
data += chunk
93-
next = data.find(b'\xff', start + 1)
94-
if next == -1:
95-
continue
96-
start = next
97-
data += stream.read(10)
9891
if data[start+1] in b'\xc0\xc2':
9992
h, w = struct.unpack('>HH', data[start+5:start+9])
10093
return {'type': 'jpg', 'width': w, 'height': h}
94+
segment_size, = struct.unpack('>H', data[start+2:start+4])
95+
data += stream.read(segment_size + 9)
96+
start = start + segment_size + 2
10197
elif chunk.startswith(b'\x00\x00\x01\x00') or chunk.startswith(b'\x00\x00\x02\x00'):
10298
img_type = 'ico' if chunk[2:3] == b'\x01' else 'cur'
10399
num_images = struct.unpack('<H', chunk[4:6])[0]

0 commit comments

Comments
 (0)