mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
If appended EOI did not work, do not keep trying
This commit is contained in:
parent
525c840b0f
commit
1059eb5376
|
@ -870,6 +870,30 @@ class TestFileJpeg:
|
||||||
with Image.open("Tests/images/hopper.jpg") as im:
|
with Image.open("Tests/images/hopper.jpg") as im:
|
||||||
assert im.getxmp() == {}
|
assert im.getxmp() == {}
|
||||||
|
|
||||||
|
@pytest.mark.timeout(timeout=1)
|
||||||
|
def test_eof(self):
|
||||||
|
# Even though this decoder never says that it is finished
|
||||||
|
# the image should still end when there is no new data
|
||||||
|
class InfiniteMockPyDecoder(ImageFile.PyDecoder):
|
||||||
|
def decode(self, buffer):
|
||||||
|
return 0, 0
|
||||||
|
|
||||||
|
decoder = InfiniteMockPyDecoder(None)
|
||||||
|
|
||||||
|
def closure(mode, *args):
|
||||||
|
decoder.__init__(mode, *args)
|
||||||
|
return decoder
|
||||||
|
|
||||||
|
Image.register_decoder("INFINITE", closure)
|
||||||
|
|
||||||
|
with Image.open(TEST_FILE) as im:
|
||||||
|
im.tile = [
|
||||||
|
("INFINITE", (0, 0, 128, 128), 0, ("RGB", 0, 1)),
|
||||||
|
]
|
||||||
|
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||||
|
im.load()
|
||||||
|
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not is_win32(), reason="Windows only")
|
@pytest.mark.skipif(not is_win32(), reason="Windows only")
|
||||||
@skip_unless_feature("jpg")
|
@skip_unless_feature("jpg")
|
||||||
|
|
|
@ -401,9 +401,10 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
"""
|
"""
|
||||||
s = self.fp.read(read_bytes)
|
s = self.fp.read(read_bytes)
|
||||||
|
|
||||||
if not s and ImageFile.LOAD_TRUNCATED_IMAGES:
|
if not s and ImageFile.LOAD_TRUNCATED_IMAGES and not hasattr(self, "_ended"):
|
||||||
# Premature EOF.
|
# Premature EOF.
|
||||||
# Pretend file is finished adding EOI marker
|
# Pretend file is finished adding EOI marker
|
||||||
|
self._ended = True
|
||||||
return b"\xFF\xD9"
|
return b"\xFF\xD9"
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
Loading…
Reference in New Issue
Block a user