mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 17:54:32 +03:00
Handle packets that cross scan lines
This commit is contained in:
parent
17d342bc4b
commit
0d729941a8
BIN
Tests/images/cross_scan_line.png
Normal file
BIN
Tests/images/cross_scan_line.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 71 B |
BIN
Tests/images/cross_scan_line.tga
Normal file
BIN
Tests/images/cross_scan_line.tga
Normal file
Binary file not shown.
|
@ -97,6 +97,11 @@ def test_id_field_rle():
|
||||||
assert im.size == (199, 199)
|
assert im.size == (199, 199)
|
||||||
|
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
|
||||||
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"
|
||||||
with Image.open(test_file) as im:
|
with Image.open(test_file) as im:
|
||||||
|
|
|
@ -20,6 +20,8 @@ int
|
||||||
ImagingTgaRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) {
|
ImagingTgaRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) {
|
||||||
int n, depth;
|
int n, depth;
|
||||||
UINT8 *ptr;
|
UINT8 *ptr;
|
||||||
|
UINT8 extra_data = 0;
|
||||||
|
int extra_bytes = 0;
|
||||||
|
|
||||||
ptr = buf;
|
ptr = buf;
|
||||||
|
|
||||||
|
@ -72,8 +74,10 @@ ImagingTgaRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state->x + n > state->bytes) {
|
if (state->x + n > state->bytes) {
|
||||||
state->errcode = IMAGING_CODEC_OVERRUN;
|
extra_bytes = n; /* full value */
|
||||||
return -1;
|
n = state->bytes - state->x;
|
||||||
|
extra_bytes -= n;
|
||||||
|
extra_data = ptr[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(state->buffer + state->x, ptr + 1, n);
|
memcpy(state->buffer + state->x, ptr + 1, n);
|
||||||
|
@ -82,6 +86,7 @@ ImagingTgaRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
|
||||||
bytes -= 1 + n;
|
bytes -= 1 + n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
state->x += n;
|
state->x += n;
|
||||||
|
|
||||||
if (state->x >= state->bytes) {
|
if (state->x >= state->bytes) {
|
||||||
|
@ -101,6 +106,24 @@ ImagingTgaRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (extra_bytes == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->x > 0) {
|
||||||
|
break; // assert
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extra_bytes >= state->bytes) {
|
||||||
|
n = state->bytes;
|
||||||
|
} else {
|
||||||
|
n = extra_bytes;
|
||||||
|
}
|
||||||
|
memcpy(state->buffer + state->x, ptr, n);
|
||||||
|
ptr += n;
|
||||||
|
extra_bytes -= n;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ptr - buf;
|
return ptr - buf;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user