mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
Merge branch 'PHP-8.3'
* PHP-8.3: Fix crash when converting array data for array in shm in xxh3
This commit is contained in:
commit
bb299a03e9
2 changed files with 21 additions and 3 deletions
|
@ -174,11 +174,14 @@ zend_always_inline static void _PHP_XXH3_Init(PHP_XXH3_64_CTX *ctx, HashTable *a
|
||||||
func_init_seed(&ctx->s, (XXH64_hash_t)Z_LVAL_P(_seed));
|
func_init_seed(&ctx->s, (XXH64_hash_t)Z_LVAL_P(_seed));
|
||||||
return;
|
return;
|
||||||
} else if (_secret) {
|
} else if (_secret) {
|
||||||
if (!try_convert_to_string(_secret)) {
|
zend_string *secret_string = zval_try_get_string(_secret);
|
||||||
|
if (UNEXPECTED(!secret_string)) {
|
||||||
|
ZEND_ASSERT(EG(exception));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t len = Z_STRLEN_P(_secret);
|
size_t len = ZSTR_LEN(secret_string);
|
||||||
if (len < PHP_XXH3_SECRET_SIZE_MIN) {
|
if (len < PHP_XXH3_SECRET_SIZE_MIN) {
|
||||||
|
zend_string_release(secret_string);
|
||||||
zend_throw_error(NULL, "%s: Secret length must be >= %u bytes, %zu bytes passed", algo_name, XXH3_SECRET_SIZE_MIN, len);
|
zend_throw_error(NULL, "%s: Secret length must be >= %u bytes, %zu bytes passed", algo_name, XXH3_SECRET_SIZE_MIN, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -186,7 +189,8 @@ zend_always_inline static void _PHP_XXH3_Init(PHP_XXH3_64_CTX *ctx, HashTable *a
|
||||||
len = sizeof(ctx->secret);
|
len = sizeof(ctx->secret);
|
||||||
php_error_docref(NULL, E_WARNING, "%s: Secret content exceeding %zu bytes discarded", algo_name, sizeof(ctx->secret));
|
php_error_docref(NULL, E_WARNING, "%s: Secret content exceeding %zu bytes discarded", algo_name, sizeof(ctx->secret));
|
||||||
}
|
}
|
||||||
memcpy((unsigned char *)ctx->secret, Z_STRVAL_P(_secret), len);
|
memcpy((unsigned char *)ctx->secret, ZSTR_VAL(secret_string), len);
|
||||||
|
zend_string_release(secret_string);
|
||||||
func_init_secret(&ctx->s, ctx->secret, len);
|
func_init_secret(&ctx->s, ctx->secret, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
14
ext/hash/tests/xxh3_convert_secret_to_string.phpt
Normal file
14
ext/hash/tests/xxh3_convert_secret_to_string.phpt
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
--TEST--
|
||||||
|
xxh3 convert secret to string should not modify (shm) array
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
try {
|
||||||
|
hash_init("xxh3", options: $x = ["secret" => 4]);
|
||||||
|
} catch (Throwable) {}
|
||||||
|
var_dump($x);
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
array(1) {
|
||||||
|
["secret"]=>
|
||||||
|
int(4)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue