mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Merge pull request #1401 from radarhere/ppm
Fixed infinite loop on truncated file
This commit is contained in:
commit
72fae49676
|
@ -93,6 +93,8 @@ class PpmImageFile(ImageFile.ImageFile):
|
||||||
s = self.fp.read(1)
|
s = self.fp.read(1)
|
||||||
if s not in b_whitespace:
|
if s not in b_whitespace:
|
||||||
break
|
break
|
||||||
|
if s == b"":
|
||||||
|
raise ValueError("File does not extend beyond magic number")
|
||||||
if s != b"#":
|
if s != b"#":
|
||||||
break
|
break
|
||||||
s = self.fp.readline()
|
s = self.fp.readline()
|
||||||
|
|
|
@ -35,6 +35,14 @@ class TestFilePpm(PillowTestCase):
|
||||||
reloaded = Image.open(f)
|
reloaded = Image.open(f)
|
||||||
self.assert_image_equal(im, reloaded)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user