diff --git a/PIL/PngImagePlugin.py b/PIL/PngImagePlugin.py index 53d38eecd..214ff9385 100644 --- a/PIL/PngImagePlugin.py +++ b/PIL/PngImagePlugin.py @@ -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": diff --git a/Tests/images/tRNS_null_1x1.png b/Tests/images/tRNS_null_1x1.png new file mode 100644 index 000000000..976eae939 Binary files /dev/null and b/Tests/images/tRNS_null_1x1.png differ diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index b3169ed25..f438e24cc 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -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"