Move jpeg-specific eof-processing to jpeg plugin

This commit is contained in:
Konstantin Kopachev 2018-03-05 21:05:56 -08:00
parent add2746ac6
commit 1e9e64c8b0
No known key found for this signature in database
GPG Key ID: CECF757E656F4F62
2 changed files with 16 additions and 1 deletions

View File

@ -221,7 +221,7 @@ class ImageFile(Image.Image):
if not s: # truncated jpeg
if LOAD_TRUNCATED_IMAGES:
s = b"\xFF\xD9" # Pretend file is finished adding EOI marker
break
else:
self.tile = []
raise IOError("image file is truncated "

View File

@ -353,6 +353,21 @@ class JpegImageFile(ImageFile.ImageFile):
else:
raise SyntaxError("no marker found")
def load_read(self, read_bytes):
"""
internal: read more image data
For premature EOF and LOAD_TRUNCATED_IMAGES adds EOI marker
so libjpeg can finish decoding
"""
s = self.fp.read(read_bytes)
if not s and ImageFile.LOAD_TRUNCATED_IMAGES:
# Premature EOF.
# Pretend file is finished adding EOI marker
return b"\xFF\xD9"
return s
def draft(self, mode, size):
if len(self.tile) != 1: