When reading past the end of a scan line, reduce bytes left

This commit is contained in:
Andrew Murray 2022-05-15 13:51:31 +10:00 committed by Hugo van Kemenade
parent 638ba163f4
commit f0353c5996
3 changed files with 5 additions and 0 deletions

Binary file not shown.

View File

@ -101,6 +101,10 @@ def test_cross_scan_line():
with Image.open("Tests/images/cross_scan_line.tga") as im: with Image.open("Tests/images/cross_scan_line.tga") as im:
assert_image_equal_tofile(im, "Tests/images/cross_scan_line.png") assert_image_equal_tofile(im, "Tests/images/cross_scan_line.png")
with Image.open("Tests/images/cross_scan_line_truncated.tga") as im:
with pytest.raises(OSError):
im.load()
def test_save(tmp_path): def test_save(tmp_path):
test_file = "Tests/images/tga_id_field.tga" test_file = "Tests/images/tga_id_field.tga"

View File

@ -120,6 +120,7 @@ ImagingTgaRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
} }
memcpy(state->buffer + state->x, ptr, n); memcpy(state->buffer + state->x, ptr, n);
ptr += n; ptr += n;
bytes -= n;
extra_bytes -= n; extra_bytes -= n;
} }
} }