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

From: Date: Thu, 26 Nov 2026 16:16:20 +0000
Subject: [php-src] master: Merge branch 'PHP-8.5' into PHP-8.6
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144227@lists.php.net to get a copy of this message
Author: Weilin Du (LamentXU123) Date: 2026-11-27T00:13:03+08:00 Commit: https://github.com/php/php-src/commit/1dc77d55b1f66fc918a0a9646117c2cc420ff00e Raw diff: https://github.com/php/php-src/commit/1dc77d55b1f66fc918a0a9646117c2cc420ff00e.diff Merge branch 'PHP-8.5' into PHP-8.6 * PHP-8.5: Fix stale string metadata in sodium_add() and sodium_increment() (#25775) Changed paths: A ext/sodium/tests/in_place_cached_string_state.phpt M NEWS M ext/sodium/libsodium.c Diff: diff --git a/NEWS b/NEWS index 347850af3d36..8222edce215f 100644 --- a/NEWS +++ b/NEWS @@ -249,6 +249,10 @@ PHP NEWS . Fixed bug GH-25530 (socket_last_error() without a socket returns an error from a previous request). (Artem Ukrainskiy) +- Sodium: + . Fixed sodium_add() and sodium_increment() retaining stale string hashes + and UTF-8 validity flags. (lacatoire) + - Standard: . Fixed bug GH-25474 (version_compare() treats large numeric parts as equal on 64-bit Windows). (lazerg, timwolla) diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c index ad15928df410..b03314352ff4 100644 --- a/ext/sodium/libsodium.c +++ b/ext/sodium/libsodium.c @@ -298,6 +298,9 @@ static void sodium_separate_string(zval *zv) { zend_string *copy = zend_string_init(Z_STRVAL_P(zv), Z_STRLEN_P(zv), 0); Z_TRY_DELREF_P(zv); ZVAL_STR(zv, copy); + } else { + /* The caller writes into the string: drop its cached hash and UTF-8 flag */ + zend_string_forget_hash_val(Z_STR_P(zv)); } } diff --git a/ext/sodium/tests/in_place_cached_string_state.phpt b/ext/sodium/tests/in_place_cached_string_state.phpt new file mode 100644 index 000000000000..1ae014d27582 --- /dev/null +++ b/ext/sodium/tests/in_place_cached_string_state.phpt @@ -0,0 +1,35 @@ +--TEST-- +sodium_add() and sodium_increment() reset the cached hash and the UTF-8 flag of the string they write +--EXTENSIONS-- +sodium +--FILE-- +<?php + +$x = 'c'; +$array = ['abc' => 1, 'bbc' => 2]; + +foreach (['sodium_add', 'sodium_increment'] as $function) { + // The hash of "abc" is cached by the lookup, then the bytes change + $string = 'ab' . $x; + var_dump(isset($array[$string])); + $function === 'sodium_add' ? sodium_add($string, "\x01\x00\x00") : sodium_increment($string); + var_dump($string === 'bbc', isset($array[$string])); +} + +// The valid UTF-8 flag is set by the match, then the bytes become invalid +$string = 'ab' . $x; +var_dump(preg_match('/./u', $string)); +sodium_add($string, "\x00\x00\x8e"); +var_dump(bin2hex($string), preg_match('/./u', $string)); + +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +int(1) +string(6) "6162f1" +bool(false)

« previous php.cvs (#144227) next »