Skip to content

Commit

Permalink
Finish once enough data has been read
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Mar 9, 2022
1 parent ae06f2e commit 9db527a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Tests/test_file_bmp.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/BmpImagePlugin.py
Expand Up @@ -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:
Expand Down

0 comments on commit 9db527a

Please sign in to comment.