]> granicus.if.org Git - php/commitdiff
MFH: catch overflow right away
authorAntony Dovgal <tony2001@php.net>
Sat, 20 Jan 2007 23:10:02 +0000 (23:10 +0000)
committerAntony Dovgal <tony2001@php.net>
Sat, 20 Jan 2007 23:10:02 +0000 (23:10 +0000)
Zend/zend_hash.c

index b547d99ee8f4c3b4e6ad8cd6fece6849ce114317..a5faafefed41f3bd5f5bce902db4d1d0215f3edf 100644 (file)
@@ -141,11 +141,16 @@ ZEND_API int _zend_hash_init(HashTable *ht, uint nSize, hash_func_t pHashFunctio
 
        SET_INCONSISTENT(HT_OK);
 
-       while ((1U << i) < nSize) {
-               i++;
+       if (nSize >= 0x80000000) {
+               /* prevent overflow */
+               ht->nTableSize = 0x80000000;
+       } else {
+               while ((1U << i) < nSize) {
+                       i++;
+               }
+               ht->nTableSize = 1 << i;
        }
 
-       ht->nTableSize = 1 << i;
        ht->nTableMask = ht->nTableSize - 1;
        ht->pDestructor = pDestructor;
        ht->arBuckets = NULL;