handle Photoshop chunks which can't be processed

This commit is contained in:
Alexander 2020-01-19 03:35:17 +03:00
parent 3841c96ec6
commit f55eb73934

View File

@ -101,37 +101,39 @@ def APP(self, marker):
# markers appear in the correct sequence. # markers appear in the correct sequence.
self.icclist.append(s) self.icclist.append(s)
elif marker == 0xFFED and s[:14] == b"Photoshop 3.0\x00": elif marker == 0xFFED and s[:14] == b"Photoshop 3.0\x00":
# parse the image resource block # Process this marker only if previous were empty
offset = 14 if not self.info.get("photoshop"):
photoshop = {} # parse the image resource block
while s[offset : offset + 4] == b"8BIM": offset = 14
offset += 4 photoshop = {}
# resource code while s[offset : offset + 4] == b"8BIM":
try: try:
code = i16(s, offset) offset += 4
except struct.error: # resource code
break code = i16(s, offset)
offset += 2 offset += 2
# resource name (usually empty) # resource name (usually empty)
name_len = i8(s[offset]) name_len = i8(s[offset])
# name = s[offset+1:offset+1+name_len] # name = s[offset+1:offset+1+name_len]
offset += 1 + name_len offset += 1 + name_len
offset += offset & 1 # align offset += offset & 1 # align
# resource data block # resource data block
size = i32(s, offset) size = i32(s, offset)
offset += 4 offset += 4
data = s[offset : offset + size] data = s[offset : offset + size]
if code == 0x03ED: # ResolutionInfo if code == 0x03ED: # ResolutionInfo
data = { data = {
"XResolution": i32(data[:4]) / 65536, "XResolution": i32(data[:4]) / 65536,
"DisplayedUnitsX": i16(data[4:8]), "DisplayedUnitsX": i16(data[4:8]),
"YResolution": i32(data[8:12]) / 65536, "YResolution": i32(data[8:12]) / 65536,
"DisplayedUnitsY": i16(data[12:]), "DisplayedUnitsY": i16(data[12:]),
} }
photoshop[code] = data photoshop[code] = data
offset += size offset += size
offset += offset & 1 # align offset += offset & 1 # align
self.info["photoshop"] = photoshop except struct.error:
break # no sufficient data
self.info["photoshop"] = photoshop
elif marker == 0xFFEE and s[:5] == b"Adobe": elif marker == 0xFFEE and s[:5] == b"Adobe":
self.info["adobe"] = i16(s, 5) self.info["adobe"] = i16(s, 5)