Skip to content

Commit

Permalink
When reading past the end of a scan line, reduce bytes left
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere authored and hugovk committed May 17, 2022
1 parent 184b73e commit c846cc8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
Binary file added Tests/images/cross_scan_line_truncated.tga
Binary file not shown.
4 changes: 4 additions & 0 deletions Tests/test_file_tga.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def test_cross_scan_line():
with Image.open("Tests/images/cross_scan_line.tga") as im:
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):
test_file = "Tests/images/tga_id_field.tga"
Expand Down
1 change: 1 addition & 0 deletions src/libImaging/TgaRleDecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ ImagingTgaRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
}
memcpy(state->buffer + state->x, ptr, n);
ptr += n;
bytes -= n;
extra_bytes -= n;
}
}
Expand Down

0 comments on commit c846cc8

Please sign in to comment.