[php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5
| From: | Daniel Scherzer | Date: | Mon, 28 Sep 2026 23:27:18 +0000 |
| Subject: | [php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141654@lists.php.net to get a copy of this message | ||
Author: Daniel Scherzer (DanielEScherzer)
Date: 2026-09-28T16:24:45-07:00
Commit: https://github.com/php/php-src/commit/90064889ef8a0c7cffc362ee01dd3427a7df0cca
Raw diff: https://github.com/php/php-src/commit/90064889ef8a0c7cffc362ee01dd3427a7df0cca.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
NEWS
ext/gd: fix undefined behavior with GD2 images with
INT_MAX-sized chunks
Changed paths:
A ext/gd/tests/createfromstring-overflow.phpt
M NEWS
M ext/gd/libgd/gd_gd2.c
Diff:
diff --git a/NEWS b/NEWS
index 7b95a9508301..21e955af50aa 100644
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,10 @@ PHP NEWS
. Fixed bug GH-23619 (cryptic error on servers that don't support TLS
session resumption on data connection). (ndossche)
+- GD:
+ . Fixed undefined behavior with GD2 images with INT_MAX-sized chunks.
+ (DanielEScherzer, cmb)
+
- Intl:
. Fixed cloning IntlDateFormatter and MessageFormatter losing PHP-side state
such as dateType, timeType, calendar and the message pattern.
diff --git a/ext/gd/libgd/gd_gd2.c b/ext/gd/libgd/gd_gd2.c
index 8e0307e5b120..f7e6e514915e 100644
--- a/ext/gd/libgd/gd_gd2.c
+++ b/ext/gd/libgd/gd_gd2.c
@@ -164,7 +164,7 @@ static int _gd2GetHeader(gdIOCtxPtr in, int *sx, int *sy, int *cs, int *vers, in
gdFree(cidx);
goto fail1;
}
- if (cidx[i].offset < 0 || cidx[i].size < 0) {
+ if (cidx[i].offset < 0 || cidx[i].size < 0 || cidx[i].size == INT_MAX) {
gdFree(cidx);
goto fail1;
}
diff --git a/ext/gd/tests/createfromstring-overflow.phpt
b/ext/gd/tests/createfromstring-overflow.phpt
new file mode 100644
index 000000000000..e79f380424ec
--- /dev/null
+++ b/ext/gd/tests/createfromstring-overflow.phpt
@@ -0,0 +1,42 @@
+--TEST--
+imagecreatefromstring overflow with compressed chunk of size INT_MAX
+--EXTENSIONS--
+gd
+--FILE--
+<?php
+
+// Documentation available at https://libgd.github.io/manuals/2.3.3/files/gd_gd2-c.html
+$fileHeaderParts = [
+ "signature" => "gd2\x00",
+ "version" => "\x00\x02",
+ "width" => "\x00\x01",
+ "height" => "\x00\x01",
+ "chunk_size" => "\x00\x40",
+ "format" => "\x00\x04", // compressed truecolor image data
+ "x_chunk_count" => "\x00\x01",
+ "y_chunk_count" => "\x00\x01",
+];
+$fileHeader = implode("", $fileHeaderParts);
+
+$chunkHeaderParts = [
+ "offset" => "\x00\x00\x00\x20",
+ "size" =>"\x7F\xFF\xFF\xFF", // INT_MAX
+];
+$chunkHeader = implode("", $chunkHeaderParts);
+
+$trueColorHeaderParts = [
+ "truecolor" => "\x01",
+ "transparent" => "\x00\x00\x00\x00",
+];
+$trueColorHeader = implode("", $trueColorHeaderParts);
+
+$source = $fileHeader . $chunkHeader . $trueColorHeader;
+$img = imagecreatefromstring($source);
+var_dump($img);
+
+?>
+--EXPECTF--
+Warning: imagecreatefromstring(): Passed data is not in "GD2" format in %s on line %d
+
+Warning: imagecreatefromstring(): Couldn't create GD Image Stream out of Data in %s on line %d
+bool(false)