This commit is contained in:
Andrew Murray 2026-02-03 21:41:50 +11:00 committed by GitHub
commit 1f14836d71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 6 additions and 6 deletions

View File

@ -85,7 +85,7 @@ class TestFileJpeg:
def test_zero(self, size: tuple[int, int], tmp_path: Path) -> None:
f = tmp_path / "temp.jpg"
im = Image.new("RGB", size)
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="cannot write empty image"):
im.save(f)
def test_app(self) -> None:

View File

@ -1244,7 +1244,7 @@ class TestFileLibTiff(LibTiffTestCase):
def test_save_zero(self, compression: str | None, tmp_path: Path) -> None:
im = Image.new("RGB", (0, 0))
out = tmp_path / "temp.tif"
with pytest.raises(SystemError):
with pytest.raises(ValueError, match="cannot write empty image"):
im.save(out, compression=compression)
def test_save_many_compressed(self, tmp_path: Path) -> None:

View File

@ -661,10 +661,6 @@ def get_sampling(im: Image.Image) -> int:
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
if im.width == 0 or im.height == 0:
msg = "cannot write empty image as JPEG"
raise ValueError(msg)
try:
rawmode = RAWMODE[im.mode]
except KeyError as e:

View File

@ -239,6 +239,10 @@ _setimage(ImagingEncoderObject *encoder, PyObject *args) {
if (!im) {
return NULL;
}
if (im->xsize == 0 || im->ysize == 0) {
PyErr_SetString(PyExc_ValueError, "cannot write empty image");
return NULL;
}
encoder->im = im;