[php-src] master: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Wed, 18 Nov 2026 21:43:45 +0000
Subject: [php-src] master: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143853@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-11-18T16:05:57-05:00 Commit: https://github.com/php/php-src/commit/d14c6e4b8637d171cc1f685c0401e3f8dc6ac821 Raw diff: https://github.com/php/php-src/commit/d14c6e4b8637d171cc1f685c0401e3f8dc6ac821.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: ext/standard: Reject out-of-range XBM dimensions Changed paths: A ext/standard/tests/image/xbm_out_of_range.phpt M NEWS M ext/standard/image.c Diff: diff --git a/NEWS b/NEWS index fd35f61b2acf..f97b7eee1247 100644 --- a/NEWS +++ b/NEWS @@ -148,6 +148,8 @@ PHP NEWS initialization). (lazerg) . Fixed memory leak in get_meta_tags() when a tag opens while an attribute value is expected. (Jorg Sowa) + . Fixed getimagesize() reporting wrapped dimensions for XBM images with + out-of-range width or height. (Ilia Alshanetsky) - Streams: . Fixed in-place URL decoding of interned strings in the HTTP and FTP diff --git a/ext/standard/image.c b/ext/standard/image.c index 041442baba5d..c7273250c221 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -1003,7 +1003,9 @@ static int php_get_xbm(php_stream *stream, struct php_gfxinfo **result) char *fline; char *iname; char *type; - int value; + char *end; + int offset; + long value; unsigned int width = 0, height = 0; if (result) { @@ -1020,25 +1022,29 @@ static int php_get_xbm(php_stream *stream, struct php_gfxinfo **result) break; } iname = estrdup(fline); /* simple way to get necessary buffer of required size */ - if (sscanf(fline, "#define %s %d", iname, &value) == 2) { - if (!(type = strrchr(iname, '_'))) { - type = iname; - } else { - type++; - } + if (sscanf(fline, "#define %s %n", iname, &offset) == 1) { + errno = 0; + value = strtol(fline + offset, &end, 10); + if (end != fline + offset && errno == 0 && value > 0 && value <= INT_MAX) { + if (!(type = strrchr(iname, '_'))) { + type = iname; + } else { + type++; + } - if (!strcmp("width", type)) { - width = (unsigned int) value; - if (height) { - efree(iname); - break; + if (!strcmp("width", type)) { + width = (unsigned int) value; + if (height) { + efree(iname); + break; + } } - } - if (!strcmp("height", type)) { - height = (unsigned int) value; - if (width) { - efree(iname); - break; + if (!strcmp("height", type)) { + height = (unsigned int) value; + if (width) { + efree(iname); + break; + } } } } diff --git a/ext/standard/tests/image/xbm_out_of_range.phpt b/ext/standard/tests/image/xbm_out_of_range.phpt new file mode 100644 index 000000000000..1252b00c945a --- /dev/null +++ b/ext/standard/tests/image/xbm_out_of_range.phpt @@ -0,0 +1,21 @@ +--TEST-- +getimagesize() rejects out-of-range XBM dimensions +--FILE-- +<?php +$path = __DIR__ . '/xbm_out_of_range.tmp.xbm'; +foreach ([['4294967298', '1'], ['1', '4294967298'], ['2147483648', '1'], ['-5', '1'], ['2147483647', '1']] as [$w, $h]) { + file_put_contents($path, "#define x_width $w\n#define x_height $h\nstatic char x_bits[] = {\n0x00 };\n"); + $info = getimagesize($path); + echo "$w x $h: ", $info ? $info[3] : 'false', "\n"; +} +?> +--CLEAN-- +<?php +@unlink(__DIR__ . '/xbm_out_of_range.tmp.xbm'); +?> +--EXPECT-- +4294967298 x 1: false +1 x 4294967298: false +2147483648 x 1: false +-5 x 1: false +2147483647 x 1: width="2147483647" height="1"

« previous php.cvs (#143853) next »