Merge pull request #1239 from juztin/master

Setting transparency value to 0 when the tRNS contains only null byte(s)
This commit is contained in:
Hugo 2015-05-27 22:37:29 +03:00
commit b350a2ac95
3 changed files with 10 additions and 0 deletions

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 B

View File

@ -354,6 +354,13 @@ class TestFilePng(PillowTestCase):
self.assert_image_equal(im2.convert('RGBA'),
im.convert('RGBA'))
def test_trns_null(self):
# Check reading images with null tRNS value, issue #1239
test_file = "Tests/images/tRNS_null_1x1.png"
im = Image.open(test_file)
self.assertEqual(im.info["transparency"], 0)
def test_save_icc_profile_none(self):
# check saving files with an ICC profile set to None (omit profile)
in_file = "Tests/images/icc_profile_none.png"