diff --git a/Tests/images/truncated_jpeg.jpg b/Tests/images/truncated_jpeg.jpg new file mode 100644 index 000000000..f4fec450d Binary files /dev/null and b/Tests/images/truncated_jpeg.jpg differ diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index f46414370..e757f151f 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -348,6 +348,22 @@ class TestFileJpeg(PillowTestCase): filename = "Tests/images/jpeg_ff00_header.jpg" Image.open(filename) + def test_truncated_jpeg_should_read_all_the_data(self): + filename = "Tests/images/truncated_jpeg.jpg" + ImageFile.LOAD_TRUNCATED_IMAGES = True + im = Image.open(filename) + im.load() + ImageFile.LOAD_TRUNCATED_IMAGES = False + self.assertIsNotNone(im.getbbox()) + + def test_truncated_jpeg_throws_IOError(self): + filename = "Tests/images/truncated_jpeg.jpg" + im = Image.open(filename) + + with self.assertRaises(IOError): + im.load() + + def _n_qtables_helper(self, n, test_file): im = Image.open(test_file) f = self.tempfile('temp.jpg')