Skip to content

Commit

Permalink
Throw TypeError if no cursors were found in .cur file
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Nov 26, 2015
1 parent ea2982f commit 0c3e224
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions PIL/CurImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def _open(self):
# 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)
Expand Down
Binary file added Tests/images/no_cursors.cur
Binary file not shown.
15 changes: 9 additions & 6 deletions Tests/test_file_cur.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

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"

# Act
im = Image.open(test_file)
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
Expand All @@ -26,6 +23,12 @@ def test_invalid_file(self):
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()
Expand Down

0 comments on commit 0c3e224

Please sign in to comment.