mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Fixed infinite loop on truncated file
This commit is contained in:
parent
cc19ca496d
commit
a0d38a3884
|
@ -93,6 +93,8 @@ class PpmImageFile(ImageFile.ImageFile):
|
|||
s = self.fp.read(1)
|
||||
if s not in b_whitespace:
|
||||
break
|
||||
if s == b"":
|
||||
raise ValueError("File does not extend beyond magic number")
|
||||
if s != b"#":
|
||||
break
|
||||
s = self.fp.readline()
|
||||
|
|
|
@ -35,6 +35,14 @@ class TestFilePpm(PillowTestCase):
|
|||
reloaded = Image.open(f)
|
||||
self.assert_image_equal(im, reloaded)
|
||||
|
||||
def test_truncated_file(self):
|
||||
path = self.tempfile('temp.pgm')
|
||||
f = open(path, 'w')
|
||||
f.write('P6')
|
||||
f.close()
|
||||
|
||||
self.assertRaises(ValueError, lambda: Image.open(path))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user