com php-src: Prevent HashTable compaction below HT_MIN_SIZE (this may lead to hash collisions).: ext /opcache/zend_persist.c
ext/opcache/zend_persist_calc .c

From: Date: Wed, 02 Sep 2015 10:03:31 +0000
Subject: com php-src: Prevent HashTable compaction below HT_MIN_SIZE (this may lead to hash collisions).: ext /opcache/zend_persist.c
ext/opcache/zend_persist_calc .c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-88855@lists.php.net to get a copy of this message
Commit: a2f8a7675bd885de131efae591a10c69f9980dd8 Author: Dmitry Stogov <dmitry@zend.com> Wed, 2 Sep 2015 13:03:31 +0300 Parents: 9c35f87e9aac29fb8f574f99edc09b344380aef0 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a2f8a7675bd885de131efae591a10c69f9980dd8 Log: Prevent HashTable compaction below HT_MIN_SIZE (this may lead to hash collisions). Changed paths: M ext/opcache/zend_persist.c M ext/opcache/zend_persist_calc.c Diff: diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index dec68b7..8e37e62 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -94,13 +94,15 @@ static void zend_hash_persist(HashTable *ht, zend_persist_func_t pPersistElement /* compact table */ void *old_data = HT_GET_DATA_ADDR(ht); Bucket *old_buckets = ht->arData; - int32_t hash_size = -(int32_t)ht->nTableMask; + int32_t hash_size; - while (hash_size >> 1 > ht->nNumUsed) { - hash_size >>= 1; - } - if (hash_size < -HT_MIN_MASK) { - hash_size = -HT_MIN_MASK; + if (ht->nNumUsed <= HT_MIN_SIZE) { + hash_size = HT_MIN_SIZE; + } else { + hash_size = -(int32_t)ht->nTableMask; + while (hash_size >> 1 > ht->nNumUsed) { + hash_size >>= 1; + } } ht->nTableMask = -hash_size; ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */ @@ -174,13 +176,15 @@ static void zend_hash_persist_immutable(HashTable *ht) /* compact table */ void *old_data = HT_GET_DATA_ADDR(ht); Bucket *old_buckets = ht->arData; - int32_t hash_size = -(int32_t)ht->nTableMask; + int32_t hash_size; - while (hash_size >> 1 > ht->nNumUsed) { - hash_size >>= 1; - } - if (hash_size < -HT_MIN_MASK) { - hash_size = -HT_MIN_MASK; + if (ht->nNumUsed <= HT_MIN_SIZE) { + hash_size = HT_MIN_SIZE; + } else { + hash_size = -(int32_t)ht->nTableMask; + while (hash_size >> 1 > ht->nNumUsed) { + hash_size >>= 1; + } } ht->nTableMask = -hash_size; ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */ diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c index 5217c2c..bad7d70 100644 --- a/ext/opcache/zend_persist_calc.c +++ b/ext/opcache/zend_persist_calc.c @@ -65,8 +65,8 @@ static void zend_hash_persist_calc(HashTable *ht, void (*pPersistElement)(zval * while (hash_size >> 1 > ht->nNumUsed) { hash_size >>= 1; } - if (hash_size < -HT_MIN_MASK) { - hash_size = -HT_MIN_MASK; + if (hash_size < HT_MIN_SIZE) { + hash_size = HT_MIN_SIZE; } ADD_SIZE(hash_size * sizeof(uint32_t) + ht->nNumUsed * sizeof(Bucket)); } else {

« previous php.cvs (#88855) next »