diff mbox series

[wrynose,v2] ghostscript: fix CVE-2026-39919

Message ID 20261201122606.3868406-1-Poornima.Lokesh@windriver.com
State New
Headers show
Series [wrynose,v2] ghostscript: fix CVE-2026-39919 | expand

Commit Message

Lokesh, Poornima Dec. 1, 2026, 12:26 p.m. UTC
Ghostscript before 10.08.0 contains a heap-based buffer overflow
vulnerability in the JPEG 2000 output adapter (base/sjpx_openjpeg.c)
that allows attackers to cause memory corruption by supplying a crafted
PDF containing a JPEG 2000 image with mismatched component subsampling
factors. When image components declare different subsampling values, the
non-samescale sub-byte-depth output path allocates a row buffer sized
for packed output but writes a full byte per output column regardless of
bit depth, overflowing the allocation and corrupting internal
chunk-allocator metadata to achieve code execution.

Fixed in 10.08.0, which master already has through the upgrade.

Reference:
[https://nvd.nist.gov/vuln/detail/CVE-2026-39919]
[https://security-tracker.debian.org/tracker/CVE-2026-39919]

Backport the patch to fix CVE-2026-39919
[https://github.com/ArtifexSoftware/ghostpdl/commit/8ddaa67d13daeca55aa13e9e3262172fa93b72f7]

Signed-off-by: Poornima Lokesh <Poornima.Lokesh@windriver.com>
---
 .../ghostscript/CVE-2026-39919.patch          | 77 +++++++++++++++++++
 .../ghostscript/ghostscript_10.06.0.bb        |  1 +
 2 files changed, 78 insertions(+)
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2026-39919.patch
diff mbox series

Patch

diff --git a/meta/recipes-extended/ghostscript/ghostscript/CVE-2026-39919.patch b/meta/recipes-extended/ghostscript/ghostscript/CVE-2026-39919.patch
new file mode 100644
index 0000000000..4b3325b7df
--- /dev/null
+++ b/meta/recipes-extended/ghostscript/ghostscript/CVE-2026-39919.patch
@@ -0,0 +1,77 @@ 
+From 0a8bf88e39db07b0751a58d6ec1cf992073e4dc1 Mon Sep 17 00:00:00 2001
+From: Ken Sharp <Ken.Sharp@artifex.com>
+Date: Mon, 24 Aug 2026 16:07:23 +0100
+Subject: [PATCH] OpenJPEG - Fix overreading bytes in some conditions.
+
+Bug #709666 "Heap buffer overflow in the JPEG 2000 (JPXDecode) output adapter via component subsampling mismatch (base/sjpx_openjpeg.c)"
+
+If we have more than one component, and the components are not the
+same scale factor, and the number of bits is less than 8, then we would
+run round a loop reading 'state->width' samples of data to the output.
+
+The problem, of course, is that if the BPS is less than 8, we don't
+want to read that many bytes, just that many samples.
+
+Fixed here by incrementing the sample count in the inner loop, so that
+we correctly count the number of samples.
+
+For completeness, also check the number of samples in side the inner
+loop so that we don't overread. We do need to run round the loop as
+many times as there are samples in a byte, because that pushes the
+data read so far to the left so that any unread data is at the right of
+the byte.
+
+This exposed an interesting bug in a regression file. It hits the
+same scale loop, but has bps equal to 10. This resulted in us reading
+no data in the old code, but in the new code reading way too much.
+
+Added a guard in decode_image to error out on images which have BPS
+which we don't support.
+
+The original issue was reported by Alex Thomas <alext@wordfence.com>
+of Wordfence Argus (AI).
+
+CVE: CVE-2026-39919
+ 
+Upstream-Status: Backport [https://github.com/ArtifexSoftware/ghostpdl/commit/8ddaa67d13daeca55aa13e9e3262172fa93b72f7]
+ 
+Signed-off-by: Poornima Lokesh <Poornima.Lokesh@windriver.com>
+---
+ base/sjpx_openjpeg.c | 10 +++++++---
+ 1 file changed, 7 insertions(+), 3 deletions(-)
+
+diff --git a/base/sjpx_openjpeg.c b/base/sjpx_openjpeg.c
+index 205d2fa71..2e6e90d7b 100644
+--- a/base/sjpx_openjpeg.c
++++ b/base/sjpx_openjpeg.c
+@@ -509,6 +509,9 @@ static int decode_image(stream_jpxd_state * const state)
+     if (state->bpp == 12)
+         state->bpp = 16;
+ 
++    if (state->bpp != 1 && state->bpp != 2 && state->bpp != 4 && state->bpp != 8 && state->bpp != 16)
++        return ERRC;
++
+     /* calculate  total data */
+     bps = state->bpp * state->out_numcomps;
+ 
+@@ -688,16 +691,17 @@ static int process_one_trunk(stream_jpxd_state * const state, stream_cursor_writ
+                 int ppbyte1 = 8/state->bpp;
+                 /* sampling required */
+                 /* only grayscale can have such bit-depth, also shift_bit = 0, bpp < 8 */
+-                for (i = 0; i < state->width; i++)
++                for (i = 0; i < state->width; )
+                 {
+-                    for (b=0; b<ppbyte1; b++)
++                    for (b=0; b<ppbyte1; b++, i++)
+                     {
+                         int dx = state->image->comps[compno].dx;
+                         int dy = state->image->comps[compno].dy;
+                         int w = state->image->comps[compno].w;
+                         int in_offset_scaled = (y_offset/dy * w) + i / dx;
+                         bt = bt<<state->bpp;
+-                        bt += state->image->comps[compno].data[in_offset_scaled] + state->sign_comps[compno];
++                        if (i < state->width)
++                            bt += state->image->comps[compno].data[in_offset_scaled] + state->sign_comps[compno];
+                     }
+                     *row++ = bt;
+                 }
diff --git a/meta/recipes-extended/ghostscript/ghostscript_10.06.0.bb b/meta/recipes-extended/ghostscript/ghostscript_10.06.0.bb
index 1363aa281e..4364ff8916 100644
--- a/meta/recipes-extended/ghostscript/ghostscript_10.06.0.bb
+++ b/meta/recipes-extended/ghostscript/ghostscript_10.06.0.bb
@@ -27,6 +27,7 @@  SRC_URI = "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/downlo
            file://0001-Fix-32-bit-build.patch \
            file://out-of-tree.patch \
            file://0001-psi-ztype.c-replace-static-const-double-with-macros-.patch \
+           file://CVE-2026-39919.patch \
            "
 
 SRC_URI[sha256sum] = "5bd6da34794928cc7e616f288e32bd0be7f9a5ca2d3c206a0af2c19a4e3a318f"