File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1345,22 +1345,16 @@ def _writePng(self, data):
13451345 Write the image *data* into the pdf file using png
13461346 predictors with Flate compression.
13471347 """
1348-
13491348 buffer = BytesIO ()
13501349 _png .write_png (data , buffer )
13511350 buffer .seek (8 )
1352- written = 0
1353- header = bytearray (8 )
13541351 while True :
1355- n = buffer .readinto (header )
1356- assert n == 8
1357- length , type = struct .unpack (b'!L4s' , bytes (header ))
1352+ length , type = struct .unpack (b'!L4s' , buffer .read (8 ))
13581353 if type == b'IDAT' :
1359- data = bytearray (length )
1360- n = buffer .readinto (data )
1361- assert n == length
1362- self .currentstream .write (bytes (data ))
1363- written += n
1354+ data = buffer .read (length )
1355+ if len (data ) != length :
1356+ raise RuntimeError ("truncated data" )
1357+ self .currentstream .write (data )
13641358 elif type == b'IEND' :
13651359 break
13661360 else :
You can’t perform that action at this time.
0 commit comments