new file mode 100644
@@ -0,0 +1,65 @@
+From a94def348a72786e433e19dbc7c8cdd5bef02e11 Mon Sep 17 00:00:00 2001
+From: Andrew Murray <radarhere@users.noreply.github.com>
+Date: Sat, 20 Jun 2026 11:53:14 +1000
+Subject: [PATCH] Validate large filter sizes when initializing RankFilter
+
+CVE: CVE-2026-59197
+Upstream-Status: Backport [https://github.com/python-pillow/Pillow/commit/cce3bdb867c77a3420261ed1bfdb6b0787ec8fc1]
+
+Signed-off-by: Rohini Sangam <rsangam@mvista.com>
+---
+ Tests/test_image_filter.py | 6 ++++++
+ src/PIL/ImageFilter.py | 3 +++
+ src/libImaging/Filter.c | 3 +++
+ 3 files changed, 12 insertions(+)
+
+diff --git a/Tests/test_image_filter.py b/Tests/test_image_filter.py
+index 47f9ffa3d..cb4c3108f 100644
+--- a/Tests/test_image_filter.py
++++ b/Tests/test_image_filter.py
+@@ -132,6 +132,12 @@ def test_rankfilter_properties() -> None:
+ assert rankfilter.size == 1
+ assert rankfilter.rank == 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)
++
+
+ def test_builtinfilter_p() -> None:
+ builtin_filter = ImageFilter.BuiltinFilter()
+diff --git a/src/PIL/ImageFilter.py b/src/PIL/ImageFilter.py
+index b2c4950d6..1a64b3c98 100644
+--- a/src/PIL/ImageFilter.py
++++ b/src/PIL/ImageFilter.py
+@@ -61,6 +61,9 @@ class Kernel(BuiltinFilter):
+ msg = "not enough coefficients in kernel"
+ raise ValueError(msg)
+ self.filterargs = size, scale, offset, kernel
++ if size * size * 4 > (2**31 - 1):
++ msg = "filter size too large"
++ raise ValueError(msg)
+
+
+ class RankFilter(Filter):
+diff --git a/src/libImaging/Filter.c b/src/libImaging/Filter.c
+index 4dcd368ca..f1d75fa3f 100644
+--- a/src/libImaging/Filter.c
++++ b/src/libImaging/Filter.c
+@@ -57,6 +57,11 @@ ImagingExpand(Imaging imIn, int xmargin, int ymargin) {
+ if (xmargin < 0 && ymargin < 0) {
+ return (Imaging)ImagingError_ValueError("bad kernel size");
+ }
++
++ int margin = xmargin > ymargin ? xmargin : ymargin;
++ if (margin > INT_MAX / (margin * (int)sizeof(FLOAT32))) {
++ return (Imaging)ImagingError_ValueError("filter size too large");
++ }
+
+ imOut = ImagingNewDirty(
+ imIn->mode, imIn->xsize + 2 * xmargin, imIn->ysize + 2 * ymargin);
+--
+2.44.4
+
@@ -14,6 +14,7 @@ SRC_URI = "git://github.com/python-pillow/Pillow.git;branch=main;protocol=https
file://CVE-2026-59198.patch \
file://CVE-2026-59204.patch \
file://CVE-2026-112393.patch \
+ file://CVE-2026-59197.patch \
"
SRCREV = "5c89d88eee199ba53f64581ea39b6a1bc52feb1a"
Pick patch from [1] also mentioned at Debian tracker in [2] [1] https://github.com/python-pillow/Pillow/commit/cce3bdb867c77a3420261ed1bfdb6b0787ec8fc1 [2] https://security-tracker.debian.org/tracker/CVE-2026-59197 Signed-off-by: Rohini Sangam <rsangam@mvista.com> --- .../python3-pillow/CVE-2026-59197.patch | 65 +++++++++++++++++++ .../python/python3-pillow_10.3.0.bb | 1 + 2 files changed, 66 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-pillow/CVE-2026-59197.patch