Setting transparency value to 0 when the tRNS contains only null byte(s)

This commit is contained in:
Justin Wilson 2015-05-22 16:37:50 -06:00
parent 77f7cfd370
commit e317a729f3

View File

@ -71,6 +71,7 @@ _MODES = {
_simple_palette = re.compile(b'^\xff+\x00\xff*$') _simple_palette = re.compile(b'^\xff+\x00\xff*$')
_null_palette = re.compile(b'^\x00*$')
# Maximum decompressed size for a iTXt or zTXt chunk. # Maximum decompressed size for a iTXt or zTXt chunk.
# Eliminates decompression bombs where compressed chunks can expand 1000x # Eliminates decompression bombs where compressed chunks can expand 1000x
@ -350,6 +351,8 @@ class PngStream(ChunkStream):
i = s.find(b"\0") i = s.find(b"\0")
if i >= 0: if i >= 0:
self.im_info["transparency"] = i self.im_info["transparency"] = i
elif _null_palette.match(s):
self.im_info["transparency"] = 0
else: else:
self.im_info["transparency"] = s self.im_info["transparency"] = s
elif self.im_mode == "L": elif self.im_mode == "L":