mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-27 08:30:05 +03:00
Fix buffer overflow for BcnEncode
This commit is contained in:
parent
1788ab7887
commit
466d228135
|
@ -511,3 +511,18 @@ def test_save_dx10_bc5(tmp_path: Path) -> None:
|
||||||
im = hopper("L")
|
im = hopper("L")
|
||||||
with pytest.raises(OSError, match="only RGB mode can be written as BC5"):
|
with pytest.raises(OSError, match="only RGB mode can be written as BC5"):
|
||||||
im.save(out, pixel_format="BC5")
|
im.save(out, pixel_format="BC5")
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"pixel_format, mode",
|
||||||
|
(
|
||||||
|
('DXT1', 'RGBA'),
|
||||||
|
('DXT3', 'RGBA'),
|
||||||
|
('BC2', 'RGBA'),
|
||||||
|
('BC3', 'RGBA'),
|
||||||
|
('BC5', 'RGB'),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_save_large_file(tmp_path: Path, pixel_format: str, mode: str) -> None:
|
||||||
|
with hopper(mode).resize((440,440)) as im:
|
||||||
|
# should not error in valgrind
|
||||||
|
im.save(tmp_path / 'img.dds', 'DDS', pixel_format=pixel_format)
|
||||||
|
|
|
@ -258,6 +258,9 @@ ImagingBcnEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
|
||||||
UINT8 *dst = buf;
|
UINT8 *dst = buf;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
if (dst + 8 >= bytes + buf) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (n == 5) {
|
if (n == 5) {
|
||||||
encode_bc3_alpha(im, state, dst, 0);
|
encode_bc3_alpha(im, state, dst, 0);
|
||||||
dst += 8;
|
dst += 8;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user