Finish once enough data has been read

This commit is contained in:
Andrew Murray 2022-03-05 09:15:07 +11:00
parent ae06f2e274
commit 9db527a473
2 changed files with 8 additions and 1 deletions

View File

@ -139,6 +139,13 @@ def test_rle8():
with Image.open("Tests/images/hopper_rle8_row_overflow.bmp") as im:
assert_image_similar_tofile(im.convert("RGB"), "Tests/images/hopper.bmp", 12)
# Signal end of bitmap before the image is finished
with open("Tests/images/bmp/g/pal8rle.bmp", "rb") as fp:
data = fp.read(1063) + b"\x01"
with Image.open(io.BytesIO(data)) as im:
with pytest.raises(ValueError):
im.load()
def test_offset():
# This image has been hexedited

View File

@ -282,7 +282,7 @@ class BmpRleDecoder(ImageFile.PyDecoder):
def decode(self, buffer):
data = bytearray()
x = 0
while True:
while len(data) < self.state.xsize * self.state.ysize:
num_pixels = self.fd.read(1)[0]
byte = self.fd.read(1)
if num_pixels: