summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Marko <peter.marko@siemens.com>2026-01-15 01:25:24 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2026-02-16 09:52:34 +0000
commit005e0f6dafc75339ba36fe663ae72ef09fd4cc81 (patch)
treeffee0ea9725420f543b8b34752fa3a89bcfe8b9d
parentf824456616843cb2b6bbb901c8ca26c4db1db275 (diff)
downloadpoky-005e0f6dafc75339ba36fe663ae72ef09fd4cc81.tar.gz
libpng: patch CVE-2026-22801
Pick comit per [1]. [1] https://github.com/pnggroup/libpng/security/advisories/GHSA-vgjq-8cw5-ggw8 (From OE-Core rev: fc0f0ecb694ae3042cff4472c62c78a7389662c6) Signed-off-by: Peter Marko <peter.marko@siemens.com> Signed-off-by: Yoann Congal <yoann.congal@smile.fr> Signed-off-by: Paul Barker <paul@pbarker.dev> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-multimedia/libpng/files/CVE-2026-22801.patch173
-rw-r--r--meta/recipes-multimedia/libpng/libpng_1.6.42.bb1
2 files changed, 174 insertions, 0 deletions
diff --git a/meta/recipes-multimedia/libpng/files/CVE-2026-22801.patch b/meta/recipes-multimedia/libpng/files/CVE-2026-22801.patch
new file mode 100644
index 0000000000..8a611ac749
--- /dev/null
+++ b/meta/recipes-multimedia/libpng/files/CVE-2026-22801.patch
@@ -0,0 +1,173 @@
1From cf155de014fc6c5cb199dd681dd5c8fb70429072 Mon Sep 17 00:00:00 2001
2From: Cosmin Truta <ctruta@gmail.com>
3Date: Sat, 10 Jan 2026 15:20:18 +0200
4Subject: [PATCH] fix: Remove incorrect truncation casts from
5 `png_write_image_*`
6
7The type of the row stride (`display->row_bytes`) is ptrdiff_t. Casting
8to png_uint_16 before division will truncate large strides, causing
9incorrect pointer arithmetic for images exceeding 65535 bytes per row.
10For bottom-up images (negative stride), the truncation also corrupts
11the sign, advancing the row pointer forward instead of backward.
12
13Remove the erroneous casts and let the compiler handle the pointer
14arithmetic correctly. Also replace `sizeof (png_uint_16)` with 2.
15
16Add regression test via `pngstest --stride-extra N` where N > 32767
17triggers the affected code paths.
18
19A NOTE ABOUT HISTORY:
20The original code in libpng 1.5.6 (2011) had no such casts. They were
21introduced in libpng 1.6.26 (2016), likely to silence compiler warnings
22on 16-bit systems where the cast would be a no-op. On 32/64-bit systems
23the cast truncates the strides above 65535 and corrupts the negative
24strides.
25
26CVE: CVE-2026-22801
27Upstream-Status: Backport [https://github.com/pnggroup/libpng/commit/cf155de014fc6c5cb199dd681dd5c8fb70429072]
28Signed-off-by: Peter Marko <peter.marko@siemens.com>
29---
30 CMakeLists.txt | 9 ++++++++-
31 contrib/libtests/pngstest.c | 29 ++++++++++++++++++++++++++++-
32 pngwrite.c | 10 +++++-----
33 tests/pngstest-large-stride | 8 ++++++++
34 4 files changed, 49 insertions(+), 7 deletions(-)
35 create mode 100755 tests/pngstest-large-stride
36
37diff --git a/CMakeLists.txt b/CMakeLists.txt
38index a8cd82402..a595ed91d 100644
39--- a/CMakeLists.txt
40+++ b/CMakeLists.txt
41@@ -1,7 +1,7 @@
42
43 # CMakeLists.txt - CMake lists for libpng
44 #
45-# Copyright (c) 2018-2024 Cosmin Truta.
46+# Copyright (c) 2018-2026 Cosmin Truta
47 # Copyright (c) 2007-2018 Glenn Randers-Pehrson.
48 # Originally written by Christian Ehrlicher, 2007.
49 #
50@@ -859,6 +859,13 @@ if(PNG_TESTS AND PNG_SHARED)
51 endforeach()
52 endforeach()
53
54+ # Regression test:
55+ # Use stride_extra > 32767 to trigger row_bytes > 65535 for linear images.
56+ png_add_test(NAME pngstest-large-stride
57+ COMMAND pngstest
58+ OPTIONS --stride-extra 33000 --tmpfile "large-stride-" --log
59+ FILES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/testpngs/rgb-alpha-16-linear.png")
60+
61 add_executable(pngunknown ${pngunknown_sources})
62 target_link_libraries(pngunknown PRIVATE png_shared)
63
64diff --git a/contrib/libtests/pngstest.c b/contrib/libtests/pngstest.c
65index ff4c2b24a..2f29afee2 100644
66--- a/contrib/libtests/pngstest.c
67+++ b/contrib/libtests/pngstest.c
68@@ -1,7 +1,7 @@
69
70 /* pngstest.c
71 *
72- * Copyright (c) 2021 Cosmin Truta
73+ * Copyright (c) 2021-2026 Cosmin Truta
74 * Copyright (c) 2013-2017 John Cunningham Bowler
75 *
76 * This code is released under the libpng license.
77@@ -3571,6 +3571,33 @@ main(int argc, char **argv)
78 opts |= NO_RESEED;
79 else if (strcmp(arg, "--fault-gbg-warning") == 0)
80 opts |= GBG_ERROR;
81+ else if (strcmp(arg, "--stride-extra") == 0)
82+ {
83+ if (c+1 < argc)
84+ {
85+ char *ep;
86+ unsigned long val = strtoul(argv[++c], &ep, 0);
87+
88+ if (ep > argv[c] && *ep == 0 && val <= 65535)
89+ stride_extra = (int)val;
90+
91+ else
92+ {
93+ fflush(stdout);
94+ fprintf(stderr, "%s: bad argument for --stride-extra: %s\n",
95+ argv[0], argv[c]);
96+ exit(99);
97+ }
98+ }
99+
100+ else
101+ {
102+ fflush(stdout);
103+ fprintf(stderr, "%s: missing argument for --stride-extra\n",
104+ argv[0]);
105+ exit(99);
106+ }
107+ }
108 else if (strcmp(arg, "--tmpfile") == 0)
109 {
110 if (c+1 < argc)
111diff --git a/pngwrite.c b/pngwrite.c
112index 08066bcc4..a95b846c8 100644
113--- a/pngwrite.c
114+++ b/pngwrite.c
115@@ -1,7 +1,7 @@
116
117 /* pngwrite.c - general routines to write a PNG file
118 *
119- * Copyright (c) 2018-2024 Cosmin Truta
120+ * Copyright (c) 2018-2026 Cosmin Truta
121 * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
122 * Copyright (c) 1996-1997 Andreas Dilger
123 * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
124@@ -1645,7 +1645,7 @@ png_write_image_16bit(png_voidp argument)
125 }
126
127 png_write_row(png_ptr, png_voidcast(png_const_bytep, display->local_row));
128- input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16));
129+ input_row += display->row_bytes / 2;
130 }
131
132 return 1;
133@@ -1771,7 +1771,7 @@ png_write_image_8bit(png_voidp argument)
134
135 png_write_row(png_ptr, png_voidcast(png_const_bytep,
136 display->local_row));
137- input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16));
138+ input_row += display->row_bytes / 2;
139 } /* while y */
140 }
141
142@@ -1796,7 +1796,7 @@ png_write_image_8bit(png_voidp argument)
143 }
144
145 png_write_row(png_ptr, output_row);
146- input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16));
147+ input_row += display->row_bytes / 2;
148 }
149 }
150
151@@ -2115,7 +2115,7 @@ png_image_write_main(png_voidp argument)
152 ptrdiff_t row_bytes = display->row_stride;
153
154 if (linear != 0)
155- row_bytes *= (sizeof (png_uint_16));
156+ row_bytes *= 2;
157
158 if (row_bytes < 0)
159 row += (image->height-1) * (-row_bytes);
160diff --git a/tests/pngstest-large-stride b/tests/pngstest-large-stride
161new file mode 100755
162index 000000000..7958c5b42
163--- /dev/null
164+++ b/tests/pngstest-large-stride
165@@ -0,0 +1,8 @@
166+#!/bin/sh
167+
168+# Regression test:
169+# Use stride_extra > 32767 to trigger row_bytes > 65535 for linear images.
170+exec ./pngstest \
171+ --stride-extra 33000 \
172+ --tmpfile "large-stride-" \
173+ --log "${srcdir}/contrib/testpngs/rgb-alpha-16-linear.png"
diff --git a/meta/recipes-multimedia/libpng/libpng_1.6.42.bb b/meta/recipes-multimedia/libpng/libpng_1.6.42.bb
index fe99e5df09..0e375a0ce8 100644
--- a/meta/recipes-multimedia/libpng/libpng_1.6.42.bb
+++ b/meta/recipes-multimedia/libpng/libpng_1.6.42.bb
@@ -22,6 +22,7 @@ SRC_URI = "${SOURCEFORGE_MIRROR}/project/${BPN}/${BPN}${LIBV}/${PV}/${BP}.tar.xz
22 file://CVE-2025-66293-01.patch \ 22 file://CVE-2025-66293-01.patch \
23 file://CVE-2025-66293-02.patch \ 23 file://CVE-2025-66293-02.patch \
24 file://CVE-2026-22695.patch \ 24 file://CVE-2026-22695.patch \
25 file://CVE-2026-22801.patch \
25" 26"
26 27
27SRC_URI[sha256sum] = "c919dbc11f4c03b05aba3f8884d8eb7adfe3572ad228af972bb60057bdb48450" 28SRC_URI[sha256sum] = "c919dbc11f4c03b05aba3f8884d8eb7adfe3572ad228af972bb60057bdb48450"