diff --git a/PIL/CurImagePlugin.py b/PIL/CurImagePlugin.py index 3825e098b..4db4c4073 100644 --- a/PIL/CurImagePlugin.py +++ b/PIL/CurImagePlugin.py @@ -66,6 +66,8 @@ class CurImageFile(BmpImagePlugin.BmpImageFile): # print "hotspot y", i16(s[6:]) # print "bytes", i32(s[8:]) # print "offset", i32(s[12:]) + if not m: + raise TypeError("No cursors were found") # load as bitmap self._bitmap(i32(m[12:]) + offset) diff --git a/Tests/images/no_cursors.cur b/Tests/images/no_cursors.cur new file mode 100644 index 000000000..a98e1035a Binary files /dev/null and b/Tests/images/no_cursors.cur differ diff --git a/Tests/test_file_cur.py b/Tests/test_file_cur.py index fa4242629..f1c077945 100644 --- a/Tests/test_file_cur.py +++ b/Tests/test_file_cur.py @@ -2,17 +2,14 @@ from helper import unittest, PillowTestCase from PIL import Image, CurImagePlugin +TEST_FILE = "Tests/images/deerstalker.cur" + class TestFileCur(PillowTestCase): def test_sanity(self): - # Arrange - test_file = "Tests/images/deerstalker.cur" + im = Image.open(TEST_FILE) - # Act - im = Image.open(test_file) - - # Assert self.assertEqual(im.size, (32, 32)) self.assertIsInstance(im, CurImagePlugin.CurImageFile) # Check some pixel colors to ensure image is loaded properly @@ -26,6 +23,12 @@ class TestFileCur(PillowTestCase): self.assertRaises(SyntaxError, lambda: CurImagePlugin.CurImageFile(invalid_file)) + no_cursors_file = "Tests/images/no_cursors.cur" + + cur = CurImagePlugin.CurImageFile(TEST_FILE) + cur.fp = open(no_cursors_file, "rb") + self.assertRaises(TypeError, cur._open) + if __name__ == '__main__': unittest.main()