mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Merge pull request #8322 from radarhere/webp
Updated error message when saving WebP with invalid width or height
This commit is contained in:
commit
dcd77b57d8
|
@ -157,6 +157,17 @@ class TestFileWebp:
|
|||
im.save(temp_file, method=0)
|
||||
assert str(e.value) == "encoding error 6"
|
||||
|
||||
@pytest.mark.skipif(sys.maxsize <= 2**32, reason="Requires 64-bit system")
|
||||
def test_write_encoding_error_bad_dimension(self, tmp_path: Path) -> None:
|
||||
temp_file = str(tmp_path / "temp.webp")
|
||||
im = Image.new("L", (16384, 16384))
|
||||
with pytest.raises(ValueError) as e:
|
||||
im.save(temp_file)
|
||||
assert (
|
||||
str(e.value)
|
||||
== "encoding error 5: Image size exceeds WebP limit of 16383 pixels"
|
||||
)
|
||||
|
||||
def test_WebPEncode_with_invalid_args(self) -> None:
|
||||
"""
|
||||
Calling encoder functions with no arguments should result in an error.
|
||||
|
|
11
src/_webp.c
11
src/_webp.c
|
@ -672,7 +672,16 @@ WebPEncode_wrapper(PyObject *self, PyObject *args) {
|
|||
|
||||
WebPPictureFree(&pic);
|
||||
if (!ok) {
|
||||
PyErr_Format(PyExc_ValueError, "encoding error %d", (&pic)->error_code);
|
||||
int error_code = (&pic)->error_code;
|
||||
char message[50] = "";
|
||||
if (error_code == VP8_ENC_ERROR_BAD_DIMENSION) {
|
||||
sprintf(
|
||||
message,
|
||||
": Image size exceeds WebP limit of %d pixels",
|
||||
WEBP_MAX_DIMENSION
|
||||
);
|
||||
}
|
||||
PyErr_Format(PyExc_ValueError, "encoding error %d%s", error_code, message);
|
||||
return NULL;
|
||||
}
|
||||
output = writer.mem;
|
||||
|
|
Loading…
Reference in New Issue
Block a user