mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Fixing compatibility with the truncated images tests
This commit is contained in:
parent
77da73c90f
commit
90378c8298
|
@ -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))
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user