[php-src] master: Fix GH-25474: version_compare() numeric parts overflow long on Windows (#25475)

From: Date: Mon, 16 Nov 2026 09:19:51 +0000
Subject: [php-src] master: Fix GH-25474: version_compare() numeric parts overflow long on Windows (#25475)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143728@lists.php.net to get a copy of this message
Author: lazerg (lazerg) Committer: Weilin Du (LamentXU123) Date: 2026-11-16T17:10:01+08:00 Commit: https://github.com/php/php-src/commit/de5c604302712362dc8d2f366a0b36066ed8dce6 Raw diff: https://github.com/php/php-src/commit/de5c604302712362dc8d2f366a0b36066ed8dce6.diff Fix GH-25474: version_compare() numeric parts overflow long on Windows (#25475) php_version_compare() parsed numeric parts with strtol() into a long, which is 32 bits on Windows. Parts above 2147483647 were clamped to LONG_MAX, so different large build numbers compared as equal. Use ZEND_STRTOL() and zend_long so the range matches PHP integers on every 64-bit platform. Add a regression test and a NEWS entry. Closes #25475 Changed paths: A ext/standard/tests/versioning/gh25474.phpt M NEWS M ext/standard/versioning.c Diff: diff --git a/NEWS b/NEWS index 64c61f8f121b..b655a47a6f15 100644 --- a/NEWS +++ b/NEWS @@ -109,6 +109,8 @@ PHP NEWS (jorgsowa) - Standard: + . Fixed bug GH-25474 (version_compare() treats large numeric parts as equal + on 64-bit Windows). (lazerg) . Fixed dns_get_record() returning partially built records for malformed DNS responses. (Marti2203) . Fixed bug GH-25387 (Uploaded files leak in request_parse_body()). diff --git a/ext/standard/tests/versioning/gh25474.phpt b/ext/standard/tests/versioning/gh25474.phpt new file mode 100644 index 000000000000..c055b69d88bf --- /dev/null +++ b/ext/standard/tests/versioning/gh25474.phpt @@ -0,0 +1,18 @@ +--TEST-- +GH-25474 (version_compare() treats numeric parts > 2147483647 as equal on Windows) +--CREDITS-- +HFigarella +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); +?> +--FILE-- +<?php +var_dump(version_compare('2147483648', '2147483647')); +var_dump(version_compare('5000000000', '6000000000')); +var_dump(version_compare('16.5-a.2-43779010004', '16.5-a.2-43192679404')); +?> +--EXPECT-- +int(1) +int(-1) +int(1) diff --git a/ext/standard/versioning.c b/ext/standard/versioning.c index f82e3d2c07dc..4b3d4180096d 100644 --- a/ext/standard/versioning.c +++ b/ext/standard/versioning.c @@ -131,7 +131,7 @@ php_version_compare(const char *orig_ver1, const char *orig_ver2) char *ver1; char *ver2; char *p1, *p2, *n1, *n2; - long l1, l2; + zend_long l1, l2; int compare = 0; if (!*orig_ver1 || !*orig_ver2) { @@ -162,8 +162,8 @@ php_version_compare(const char *orig_ver1, const char *orig_ver2) } if (isdigit((unsigned char)*p1) && isdigit((unsigned char)*p2)) { /* compare element numerically */ - l1 = strtol(p1, NULL, 10); - l2 = strtol(p2, NULL, 10); + l1 = ZEND_STRTOL(p1, NULL, 10); + l2 = ZEND_STRTOL(p2, NULL, 10); compare = ZEND_NORMALIZE_BOOL(l1 - l2); } else if (!isdigit((unsigned char)*p1) && !isdigit((unsigned char)*p2)) { /* compare element names */

« previous php.cvs (#143728) next »