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

index 03b682717f482d9004afecfdfa8205e40fd6dbb8..944743ea7b884aa6e5025624a1b56a679a3b5fbf 100644 (file)
@@ -166,11 +166,16 @@ ZEND_API int _zend_u_hash_init(HashTable *ht, uint nSize, hash_func_t pHashFunct
 
        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;