File tree Expand file tree Collapse file tree 1 file changed +5
-11
lines changed Expand file tree Collapse file tree 1 file changed +5
-11
lines changed Original file line number Diff line number Diff line change @@ -1345,22 +1345,16 @@ def _writePng(self, data):
1345
1345
Write the image *data* into the pdf file using png
1346
1346
predictors with Flate compression.
1347
1347
"""
1348
-
1349
1348
buffer = BytesIO ()
1350
1349
_png .write_png (data , buffer )
1351
1350
buffer .seek (8 )
1352
- written = 0
1353
- header = bytearray (8 )
1354
1351
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 ))
1358
1353
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 )
1364
1358
elif type == b'IEND' :
1365
1359
break
1366
1360
else :
You can’t perform that action at this time.
0 commit comments