Merge pull request #1794 from radarhere/spiderimageplugin

SpiderImagePlugin: raise an error when seeking in a non-stack file
This commit is contained in:
wiredfool 2016-04-04 02:07:41 -07:00
commit ca5e22b59a
2 changed files with 13 additions and 1 deletions

View File

@ -173,7 +173,7 @@ class SpiderImageFile(ImageFile.ImageFile):
def seek(self, frame): def seek(self, frame):
if self.istack == 0: if self.istack == 0:
return raise EOFError("attempt to seek in a non-stack file")
if frame >= self._nimages: if frame >= self._nimages:
raise EOFError("attempt to seek past end of file") raise EOFError("attempt to seek past end of file")
self.stkoffset = self.hdrlen + frame * (self.hdrlen + self.imgbytes) self.stkoffset = self.hdrlen + frame * (self.hdrlen + self.imgbytes)

View File

@ -1,6 +1,7 @@
from helper import unittest, PillowTestCase, hopper from helper import unittest, PillowTestCase, hopper
from PIL import Image from PIL import Image
from PIL import ImageSequence
from PIL import SpiderImagePlugin from PIL import SpiderImagePlugin
TEST_FILE = "Tests/images/hopper.spider" TEST_FILE = "Tests/images/hopper.spider"
@ -85,6 +86,17 @@ class TestImageSpider(PillowTestCase):
self.assertRaises(IOError, lambda: Image.open(invalid_file)) self.assertRaises(IOError, lambda: Image.open(invalid_file))
def test_nonstack_file(self):
im = Image.open(TEST_FILE)
self.assertRaises(EOFError, lambda: im.seek(0))
def test_nonstack_dos(self):
im = Image.open(TEST_FILE)
for i, frame in enumerate(ImageSequence.Iterator(im)):
if i > 1:
self.fail("Non-stack DOS file test failed")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()