[php-src] master: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Weilin Du | Date: | Thu, 26 Nov 2026 12:01:04 +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-144212@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Date: 2026-11-26T19:55:24+08:00
Commit: https://github.com/php/php-src/commit/c70d50d5717b0095de674fbc398ed2c6e313b7f9
Raw diff: https://github.com/php/php-src/commit/c70d50d5717b0095de674fbc398ed2c6e313b7f9.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
Fix hash() and hash_file() hanging on invalid xxh3/xxh128 options (#25777)
Changed paths:
A ext/hash/tests/xxh3_invalid_options_large_input.phpt
M NEWS
M ext/hash/hash.c
Diff:
diff --git a/NEWS b/NEWS
index 732dafd8c1f0..347850af3d36 100644
--- a/NEWS
+++ b/NEWS
@@ -99,6 +99,10 @@ PHP NEWS
. Fixed bug GH-25584 (JIT frees the string returned by gettext(),
dgettext() or dcgettext() while it is still in use). (Ilia Alshanetsky)
+- Hash:
+ . Fixed hash() and hash_file() hanging on invalid xxh3/xxh128 options.
+ (lacatoire)
+
- Intl:
. Fixed NumberFormatter::getSymbol(), setSymbol(), getAttribute() and
setAttribute() accepting out-of-range values that truncate to a valid one.
diff --git a/ext/hash/hash.c b/ext/hash/hash.c
index 8a4e857c9c1f..732b0baa2dc7 100644
--- a/ext/hash/hash.c
+++ b/ext/hash/hash.c
@@ -373,6 +373,14 @@ static void php_hash_do_hash(
context = php_hash_alloc_context(ops);
ops->hash_init(context, args);
+ if (UNEXPECTED(EG(exception))) {
+ /* The options were rejected, the context is not usable */
+ php_hash_free_context(ops, context);
+ if (stream) {
+ php_stream_close(stream);
+ }
+ RETURN_THROWS();
+ }
if (isfilename) {
char buf[1024];
diff --git a/ext/hash/tests/xxh3_invalid_options_large_input.phpt
b/ext/hash/tests/xxh3_invalid_options_large_input.phpt
new file mode 100644
index 000000000000..ab010dd3924f
--- /dev/null
+++ b/ext/hash/tests/xxh3_invalid_options_large_input.phpt
@@ -0,0 +1,42 @@
+--TEST--
+hash(), hash_file(): invalid xxh3/xxh128 options throw for a large input instead of hanging
+--FILE--
+<?php
+$file = __DIR__ . '/xxh3_invalid_options_large_input.bin';
+file_put_contents($file, str_repeat('z', 5000));
+
+foreach (['xxh3', 'xxh128'] as $algo) {
+ foreach ([256, 300, 5000] as $n) {
+ try {
+ hash($algo, str_repeat('z', $n), false, ['secret' =>
'short']);
+ } catch (Throwable $e) {
+ echo $algo, ' ', $n, ': ', $e::class, ': ',
$e->getMessage(), "\n";
+ }
+ }
+ try {
+ hash($algo, str_repeat('z', 5000), false, ['seed' => 1,
'secret' => str_repeat('k', 136)]);
+ } catch (Throwable $e) {
+ echo $algo, ' seed and secret: ', $e::class, ': ', $e->getMessage(),
"\n";
+ }
+ try {
+ hash_file($algo, $file, false, ['secret' => 'short']);
+ } catch (Throwable $e) {
+ echo $algo, ' file: ', $e::class, ': ', $e->getMessage(),
"\n";
+ }
+}
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/xxh3_invalid_options_large_input.bin');
+?>
+--EXPECT--
+xxh3 256: Error: xxh3: Secret length must be >= 136 bytes, 5 bytes passed
+xxh3 300: Error: xxh3: Secret length must be >= 136 bytes, 5 bytes passed
+xxh3 5000: Error: xxh3: Secret length must be >= 136 bytes, 5 bytes passed
+xxh3 seed and secret: Error: xxh3: Only one of seed or secret is to be passed for initialization
+xxh3 file: Error: xxh3: Secret length must be >= 136 bytes, 5 bytes passed
+xxh128 256: Error: xxh128: Secret length must be >= 136 bytes, 5 bytes passed
+xxh128 300: Error: xxh128: Secret length must be >= 136 bytes, 5 bytes passed
+xxh128 5000: Error: xxh128: Secret length must be >= 136 bytes, 5 bytes passed
+xxh128 seed and secret: Error: xxh128: Only one of seed or secret is to be passed for
initialization
+xxh128 file: Error: xxh128: Secret length must be >= 136 bytes, 5 bytes passed