Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Tests/test_image_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ def test_rankfilter_properties() -> None:
with pytest.raises(ValueError, match="bad filter size"):
ImageFilter.MinFilter(2)

with pytest.raises(ValueError, match="filter size too large"):
ImageFilter.RankFilter(23171, 1)
im = Image.new("1", (1, 1))
with pytest.raises(ValueError, match="filter size too large"):
im.im.expand(23171)

with pytest.raises(ValueError, match="bad rank value"):
ImageFilter.RankFilter(1, 1)

Expand Down
3 changes: 3 additions & 0 deletions src/PIL/ImageFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def __init__(self, size: int, rank: int) -> None:
if size % 2 == 0:
msg = "bad filter size"
raise ValueError(msg)
if size * size * 4 > (2**31 - 1):
msg = "filter size too large"
raise ValueError(msg)
if rank < 0 or rank >= size * size:
msg = "bad rank value"
raise ValueError(msg)
Expand Down
3 changes: 3 additions & 0 deletions src/libImaging/Filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ ImagingExpand(Imaging imIn, int margin) {
if (margin < 0) {
return (Imaging)ImagingError_ValueError("bad kernel size");
}
if (margin > INT_MAX / (margin * (int)sizeof(FLOAT32))) {
return (Imaging)ImagingError_ValueError("filter size too large");
}

imOut =
ImagingNewDirty(imIn->mode, imIn->xsize + 2 * margin, imIn->ysize + 2 * margin);
Expand Down
Loading