From fef3ceb2c02ef241a508ee020fe2617e10e33e42 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sun, 20 Jul 2014 01:50:05 +0300 Subject: [PATCH] If we can't read a file due to unsupported compression, raise an error --- PIL/SgiImagePlugin.py | 10 +++++----- Tests/test_file_sgi.py | 18 +++--------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/PIL/SgiImagePlugin.py b/PIL/SgiImagePlugin.py index bf3c18a43..2b8fcd8e4 100644 --- a/PIL/SgiImagePlugin.py +++ b/PIL/SgiImagePlugin.py @@ -45,7 +45,7 @@ class SgiImageFile(ImageFile.ImageFile): # HEAD s = self.fp.read(512) if i16(s) != 474: - raise SyntaxError("not an SGI image file") + raise ValueError("Not an SGI image file") # relevant header entries compression = i8(s[2]) @@ -61,7 +61,7 @@ class SgiImageFile(ImageFile.ImageFile): elif layout == (1, 3, 4): self.mode = "RGBA" else: - raise SyntaxError("unsupported SGI image mode") + raise ValueError("Unsupported SGI image mode") # size self.size = i16(s[6:]), i16(s[8:]) @@ -76,8 +76,7 @@ class SgiImageFile(ImageFile.ImageFile): ("raw", (0, 0)+self.size, offset, (layer, 0, -1))) offset = offset + pagesize elif compression == 1: - self.tile = [ - ("sgi_rle", (0, 0)+self.size, 512, (self.mode, 0, -1))] + raise ValueError("SGI RLE encoding not supported") # # registry @@ -87,5 +86,6 @@ Image.register_open("SGI", SgiImageFile, _accept) Image.register_extension("SGI", ".bw") Image.register_extension("SGI", ".rgb") Image.register_extension("SGI", ".rgba") - Image.register_extension("SGI", ".sgi") + +# End of file diff --git a/Tests/test_file_sgi.py b/Tests/test_file_sgi.py index e94f0d989..84b184b63 100644 --- a/Tests/test_file_sgi.py +++ b/Tests/test_file_sgi.py @@ -5,44 +5,32 @@ from PIL import Image class TestFileSgi(PillowTestCase): - def sanity(self, filename, expected_mode, expected_size=(128, 128)): - # Act - im = Image.open(filename) - - # Assert - self.assertEqual(im.mode, expected_mode) - self.assertEqual(im.size, expected_size) - def test_rgb(self): # Arrange # Created with ImageMagick then renamed: # convert lena.ppm lena.sgi test_file = "Tests/images/lena.rgb" - expected_mode = "RGB" # Act / Assert - self.sanity(test_file, expected_mode) + self.assertRaises(ValueError, lambda: Image.open(test_file)) def test_l(self): # Arrange # Created with ImageMagick then renamed: # convert lena.ppm -monochrome lena.sgi test_file = "Tests/images/lena.bw" - expected_mode = "L" # Act / Assert - self.sanity(test_file, expected_mode) + self.assertRaises(ValueError, lambda: Image.open(test_file)) def test_rgba(self): # Arrange # Created with ImageMagick: # convert transparent.png transparent.sgi test_file = "Tests/images/transparent.sgi" - expected_mode = "RGBA" - expected_size = (200, 150) # Act / Assert - self.sanity(test_file, expected_mode, expected_size) + self.assertRaises(ValueError, lambda: Image.open(test_file)) if __name__ == '__main__':