php-src
php-src copied to clipboard
version_compare() treats numeric parts > 2147483647 as equal on Windows (32-bit long)
Description
On Windows x64, version_compare() returns 0 for any two numeric parts larger than 2^31-1. Linux x64 is correct.
It looks like the numeric parts go through strtol(), and long is 32 bits on Windows (LLP64), so both values clamp
to LONG_MAX and compare equal.
Test script (php -n test.php):
0); Resulted in this output (Windows x64, 8.5.12 NTS and 8.6.0RC7 NTS, VS 2026 builds): version_compare(2147483647, 2147483646) = 1, expected 1 version_compare(2147483648, 2147483647) = 0, expected 1 version_compare(5000000000, 6000000000) = 0, expected -1 version_compare(16.5-a.2-43779010004, 16.5-a.2-43192679404) = 0, expected 1 But I expected this output instead (what PHP 8.4 on Linux x64 gives): 1, 1, -1, 1 Real-world impact: Jetpack Beta nightly versions look like "16.5-a.2-43779010004-gaf939823" (11-digit CI build number). Composer\Semver\Comparator (version_compare underneath) says two nightlies are equal, so WordPress sites on Windows/IIS never get a new nightly until the alpha number changes. Linux sites update normally. Possible fix: parse the numeric parts with ZEND_STRTOL / zend_long (64-bit on Windows x64) instead of strtol/long. ### PHP Version ```plain 8.5.12 (also 8.6.0) ``` ### Operating System Windows Server (x64), IIS 10, NTS builds