From 0c3e2245377f7a5be21628176540880ab5fb1306 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 26 Nov 2015 19:56:41 +1100 Subject: [PATCH] Throw TypeError if no cursors were found in .cur file --- PIL/CurImagePlugin.py | 2 ++ Tests/images/no_cursors.cur | Bin 0 -> 6 bytes Tests/test_file_cur.py | 15 +++++++++------ 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 Tests/images/no_cursors.cur 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 0000000000000000000000000000000000000000..a98e1035a778f4c7e319491a5c9fdb25ca8272ab GIT binary patch literal 6 NcmZQzU}9ik0000E00RI3 literal 0 HcmV?d00001 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()