Commit de5c6043027 for php
commit de5c604302712362dc8d2f366a0b36066ed8dce6
Author: lazerg <lazerg2@gmail.com>
Date: Mon Nov 16 17:10:01 2026 +0800
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
diff --git a/NEWS b/NEWS
index 64c61f8f121..b655a47a6f1 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 00000000000..c055b69d88b
--- /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 f82e3d2c07d..4b3d4180096 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 */