Fixing compatibility with the truncated images tests

This commit is contained in:
wiredfool 2016-04-04 05:40:37 -07:00
parent 77da73c90f
commit 90378c8298
2 changed files with 17 additions and 15 deletions

View File

@ -108,7 +108,7 @@ class ChunkStream(object):
def read(self):
"Fetch a new chunk. Returns header information."
cid = None
try:
if self.queue:
cid, pos, length = self.queue[-1]
del self.queue[-1]
@ -118,8 +118,6 @@ class ChunkStream(object):
cid = s[4:]
pos = self.fp.tell()
length = i32(s)
except struct.error:
SyntaxError("truncated PNG file (chunk %s)" % repr(cid))
if not is_cid(cid):
raise SyntaxError("broken PNG file (chunk %s)" % repr(cid))
@ -165,7 +163,11 @@ class ChunkStream(object):
cids = []
while True:
try:
cid, pos, length = self.read()
except struct.error:
raise IOError("truncated PNG file")
if cid == endchunk:
break
self.crc(cid, ImageFile._safe_read(self.fp, length))

View File

@ -256,7 +256,7 @@ class TestFilePng(PillowTestCase):
def test_verify_struct_error(self):
# Check open/load/verify exception (#1755)
# offsets to test, -10: breaks in i32() in read.
# offsets to test, -10: breaks in i32() in read. (IOError)
# -13: breaks in crc, txt chunk.
# -14: malformed chunk
@ -266,7 +266,7 @@ class TestFilePng(PillowTestCase):
im = Image.open(BytesIO(test_file))
self.assertTrue(im.fp is not None)
self.assertRaises(SyntaxError, im.verify)
self.assertRaises((IOError, SyntaxError), im.verify)
def test_roundtrip_dpi(self):