diff mbox series

[meta-python,wrynose] python3-pillow:fix CVE-2026-112403 CVE-2026-112398

Message ID 20261201135855.119033-1-Roopa.Kalmath@windriver.com
State New
Headers show
Series [meta-python,wrynose] python3-pillow:fix CVE-2026-112403 CVE-2026-112398 | expand

Commit Message

Kalmath, Roopa Dec. 1, 2026, 1:58 p.m. UTC
Reject JPEG streams whose scanlines are wider or have more components
(#10131).

Upstream commit:
[https://github.com/python-pillow/Pillow/commit/242a059aedc1935097d9aa1dc3f099750467ba75]

Signed-off-by: Roopa Kalmath <Roopa.Kalmath@windriver.com>
---
 .../CVE-2026-112403_CVE-2026-112398.patch     | 80 +++++++++++++++++++
 .../python/python3-pillow_12.2.0.bb           |  1 +
 2 files changed, 81 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-pillow/CVE-2026-112403_CVE-2026-112398.patch
diff mbox series

Patch

diff --git a/meta-python/recipes-devtools/python/python3-pillow/CVE-2026-112403_CVE-2026-112398.patch b/meta-python/recipes-devtools/python/python3-pillow/CVE-2026-112403_CVE-2026-112398.patch
new file mode 100644
index 0000000000..06e7d6031e
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-pillow/CVE-2026-112403_CVE-2026-112398.patch
@@ -0,0 +1,80 @@ 
+From 242a059aedc1935097d9aa1dc3f099750467ba75 Mon Sep 17 00:00:00 2001
+From: Andrew Murray <3112309+radarhere@users.noreply.github.com>
+Date: Tue, 6 Oct 2026 16:25:03 +1100
+Subject: [PATCH] Reject JPEG streams whose scanlines are wider or have more
+ components (#10131)
+
+Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
+Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
+Co-authored-by: Jeffrey 'Alex' Clark <aclark@aclark.net>
+
+CVE: CVE-2026-112403 CVE-2026-112398
+
+Upstream-Status: Backport [https://github.com/python-pillow/Pillow/commit/242a059aedc1935097d9aa1dc3f099750467ba75]
+
+Backport Changes:
+Context-adapted to the Pillow 12.2.0 tree. The upstream commit targets
+Pillow main. The functional security change is carried in this file:
+   - src/libImaging/JpegDecode.c
+     (ImagingJpegDecode: reject the stream when output_width exceeds
+     the tile width, or when output_components * output_width exceeds the
+     scanline buffer size, before decoding scanlines.)
+     The upstream hunk applied unchanged, with no offset and no change
+     to the logic.
+
+Test changes:
+   - Tests/test_file_jpeg.py: test_wider_than_tile is carried over from
+     upstream. The test body is unchanged. Only the hunk context was
+     adjusted, because the @mark_if_feature_version decorator sits
+     between test_truncated_jpeg_throws_oserror and test_qtables in
+     12.2.0, so the test is inserted above that decorator.
+
+No functional difference from upstream in the security fix.
+
+Signed-off-by: Roopa Kalmath <Roopa.Kalmath@windriver.com>
+---
+ Tests/test_file_jpeg.py     |  8 ++++++++
+ src/libImaging/JpegDecode.c | 11 +++++++++++
+ 2 files changed, 19 insertions(+)
+
+diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py
+index 5103a76..e5ceaba 100644
+--- a/Tests/test_file_jpeg.py
++++ b/Tests/test_file_jpeg.py
+@@ -559,6 +559,14 @@ class TestFileJpeg:
+             # Test that the error is raised if loaded a second time
+             with pytest.raises(OSError):
+                 im.load()
++    
++    def test_wider_than_tile(self) -> None:
++        # The decoder's scanline buffer is sized from the tile extents,
++        # so a JPEG wider than its tile must be rejected
++        with Image.open(TEST_FILE) as im:
++            im.tile = [im.tile[0]._replace(extents=(0, 0, 64, 64))]
++            with pytest.raises(OSError, match="broken data stream"):
++                im.load()
+ 
+     @mark_if_feature_version(
+         pytest.mark.valgrind_known_error, "libjpeg_turbo", "2.0", reason="Known Failing"
+diff --git a/src/libImaging/JpegDecode.c b/src/libImaging/JpegDecode.c
+index 05cb375..bf12ea9 100644
+--- a/src/libImaging/JpegDecode.c
++++ b/src/libImaging/JpegDecode.c
+@@ -241,6 +241,17 @@ ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t by
+                 break;
+             }
+ 
++            /* The scanline buffer was sized from the tile extents and the
++               unpacker, not from the JPEG header, so make sure the lines
++               libjpeg is about to produce actually fit in it. */
++            if (context->cinfo.output_width > (JDIMENSION)state->xsize ||
++                (size_t)context->cinfo.output_components * context->cinfo.output_width >
++                    (size_t)state->bytes) {
++                jpeg_destroy_decompress(&context->cinfo);
++                state->errcode = IMAGING_CODEC_BROKEN;
++                return -1;
++            }
++
+             state->state++;
+             /* fall through */
+ 
diff --git a/meta-python/recipes-devtools/python/python3-pillow_12.2.0.bb b/meta-python/recipes-devtools/python/python3-pillow_12.2.0.bb
index f1d5b66434..150fd1cd2e 100644
--- a/meta-python/recipes-devtools/python/python3-pillow_12.2.0.bb
+++ b/meta-python/recipes-devtools/python/python3-pillow_12.2.0.bb
@@ -18,6 +18,7 @@  SRC_URI = "git://github.com/python-pillow/Pillow.git;branch=main;protocol=https;
            file://CVE-2026-59203.patch \
            file://CVE-2026-59205.patch \
            file://CVE-2026-112393.patch \
+           file://CVE-2026-112403_CVE-2026-112398.patch \
            "
 SRCREV = "3c41c095064200a02672d89cc5ff629eaf4b0d4f"