mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Raise a specific exception if no data is found for an MPO frame
This commit is contained in:
parent
a9fc1b66b1
commit
47b2ae9a63
BIN
Tests/images/sugarshack_no_data.mpo
Normal file
BIN
Tests/images/sugarshack_no_data.mpo
Normal file
Binary file not shown.
After Width: | Height: | Size: 117 KiB |
|
@ -113,6 +113,13 @@ class TestFileMpo(PillowTestCase):
|
|||
self.assertEqual(mpinfo[45056], b"0100")
|
||||
self.assertEqual(mpinfo[45057], 2)
|
||||
|
||||
def test_mp_no_data(self):
|
||||
# This image has been manually hexedited to have the second frame
|
||||
# beyond the end of the file
|
||||
with Image.open("Tests/images/sugarshack_no_data.mpo") as im:
|
||||
with self.assertRaises(ValueError):
|
||||
im.seek(1)
|
||||
|
||||
def test_mp_attribute(self):
|
||||
for test_file in test_files:
|
||||
with Image.open(test_file) as im:
|
||||
|
|
|
@ -82,7 +82,10 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile):
|
|||
self.offset = self.__mpoffsets[frame]
|
||||
|
||||
self.fp.seek(self.offset + 2) # skip SOI marker
|
||||
if i16(self.fp.read(2)) == 0xFFE1: # APP1
|
||||
segment = self.fp.read(2)
|
||||
if not segment:
|
||||
raise ValueError("No data found for frame")
|
||||
if i16(segment) == 0xFFE1: # APP1
|
||||
n = i16(self.fp.read(2)) - 2
|
||||
self.info["exif"] = ImageFile._safe_read(self.fp, n)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user