From dac2b060e4c55db2f1b309125c9506ecc8f3200e Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Wed, 18 Mar 2015 22:25:55 +0100 Subject: [PATCH] Remove bogus ZEND_ASSERT(hash != 0) There's always a possibility that the has will end up as equal to zero due to overflowing. See the tests for strings whose hash overflow. Yes, there's a check for whether the hash already was calculated... and strings with a hash equal to zero always need the hash recalculated, in one of 2^32 respectively 2^64 cases - which should not be a major issue. --- Zend/tests/array_hash_zero.phpt | 20 ++++++++++++++++++++ Zend/zend_string.h | 1 - 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/array_hash_zero.phpt diff --git a/Zend/tests/array_hash_zero.phpt b/Zend/tests/array_hash_zero.phpt new file mode 100644 index 0000000000..337cdfd1a2 --- /dev/null +++ b/Zend/tests/array_hash_zero.phpt @@ -0,0 +1,20 @@ +--TEST-- +Accept hashes being equal to zero +--FILE-- + 32, + "\xf7\x17\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x6b\x03\x6a\x13\x63\x17\x6b\x1d\x67" => 64, +]; + +foreach ($hashes as $hash => $bits) { + var_dump($hashes[$hash], $bits); +} + +?> +--EXPECT-- +int(32) +int(32) +int(64) +int(64) diff --git a/Zend/zend_string.h b/Zend/zend_string.h index 746f4b3bcf..b7605efc09 100644 --- a/Zend/zend_string.h +++ b/Zend/zend_string.h @@ -284,7 +284,6 @@ static zend_always_inline zend_ulong zend_inline_hash_func(const char *str, size EMPTY_SWITCH_DEFAULT_CASE() } - ZEND_ASSERT(hash != 0); return hash; } -- 2.40.0