From ded14572a180142dd3c75fd55daf6d873255daf0 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 21 Jan 2017 14:47:59 +1100 Subject: [PATCH] Added more tests for PNG chunk ordering --- Tests/test_file_png.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index fc6b07699..8af5afe2f 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -500,7 +500,7 @@ class TestFilePng(PillowTestCase): def test_chunk_order(self): im = Image.open("Tests/images/icc_profile.png") test_file = self.tempfile("temp.png") - im.convert("P").save(test_file) + im.convert("P").save(test_file, dpi=(100, 100)) chunks = [] fp = open(test_file, "rb") @@ -514,7 +514,20 @@ class TestFilePng(PillowTestCase): except EOFError: break png.crc(cid, s) + + # https://www.w3.org/TR/PNG/#5ChunkOrdering + # IHDR - shall be first + self.assertEqual(chunks.index(b"IHDR"), 0) + # PLTE - before first IDAT + self.assertLess(chunks.index(b"PLTE"), chunks.index(b"IDAT")) + # iCCP - before PLTE and IDAT self.assertLess(chunks.index(b"iCCP"), chunks.index(b"PLTE")) + self.assertLess(chunks.index(b"iCCP"), chunks.index(b"IDAT")) + # tRNS - after PLTE, before IDAT + self.assertGreater(chunks.index(b"tRNS"), chunks.index(b"PLTE")) + self.assertLess(chunks.index(b"tRNS"), chunks.index(b"IDAT")) + # pHYs - before IDAT + self.assertLess(chunks.index(b"pHYs"), chunks.index(b"IDAT")) if __name__ == '__main__':