From b38c32ed70e6cd425dd1af80df2f7d2d7364fc06 Mon Sep 17 00:00:00 2001 From: Stephen Arthur Date: Wed, 6 Apr 2016 18:47:51 -0700 Subject: [PATCH 1/2] Valid range for baseline jpeg qtables 0 to 255, fixed issue from using signed char instead of unsigned char. added test --- PIL/JpegImagePlugin.py | 2 +- Tests/test_file_jpeg.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/PIL/JpegImagePlugin.py b/PIL/JpegImagePlugin.py index 386939ba7..0ed1fc73f 100644 --- a/PIL/JpegImagePlugin.py +++ b/PIL/JpegImagePlugin.py @@ -640,7 +640,7 @@ def _save(im, fp, filename): try: if len(table) != 64: raise - table = array.array('b', table) + table = array.array('B', table) except TypeError: raise ValueError("Invalid quantization table") else: diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 7b60f60b1..342fe74db 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -314,6 +314,10 @@ class TestFileJpeg(PillowTestCase): 30) self.assert_image_similar(im, self.roundtrip(im, qtables='keep'), 30) + # valid bounds for baseline qtable + bounds_qtable = [int(s) for s in ("255 0 " * 32).split(None)] + self.roundtrip(im, qtables=[bounds_qtable]) + # values from wizard.txt in jpeg9-a src package. standard_l_qtable = [int(s) for s in """ 16 11 10 16 24 40 51 61 From 5025bdd4879a16f794c109e4b8d87bd29869bab5 Mon Sep 17 00:00:00 2001 From: Stephen Arthur Date: Thu, 7 Apr 2016 09:35:14 -0700 Subject: [PATCH 2/2] Valid range for baseline jpeg qtables 1 to 255, fixed overflow from using signed char instead of unsigned char. added test --- Tests/test_file_jpeg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 342fe74db..3b2e6cb20 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -315,7 +315,7 @@ class TestFileJpeg(PillowTestCase): self.assert_image_similar(im, self.roundtrip(im, qtables='keep'), 30) # valid bounds for baseline qtable - bounds_qtable = [int(s) for s in ("255 0 " * 32).split(None)] + bounds_qtable = [int(s) for s in ("255 1 " * 32).split(None)] self.roundtrip(im, qtables=[bounds_qtable]) # values from wizard.txt in jpeg9-a src package.