hash冲突导致ddos,详细跟踪

来源:互联网 发布:淘宝怎么拒收 编辑:程序博客网 时间:2024/05/17 06:38

 1<?php

  2$size = 4;

  3$array = array();

  4for ($key = 0, $maxKey = ($size - 1) * $size; $key <= $maxKey; $key +=$size) {

 5     $array[$key] = 0;

  6 }

通过打印p *execute_data->opline->handler可以获得

 ZEND_INIT_ARRAY_SPEC_UNUSED_UNUSED_HANDLER

 //初始化数组

 ZEND_ASSIGN_DIM_SPEC_CV_CV_HANDLER

        zend_fetch_dimension_address

                   zend_fetch_dimension_address_inner

                            if(zend_hash_index_find(ht, index, (void **) &retval) == FAILURE) {

                                     zend_hash_index_update(ht,index, &new_zval, sizeof(zval *), (void **) &retval);

                            }

zend_hash_index_update最终走的是

_zend_hash_index_update_or_next_insert

 

去掉插入之前的zend_hash_index_find

插入 65536 个恶意的元素需要 29.089669942856 秒

插入 65536 个普通元素需要 0.018018960952759 秒

执行以后发现仅降低了一般,还有29秒

另外的时间耽搁在了

在插入之前还有一次hash查找进行update的过程,并把指针指向当前index的链表结尾

_zend_hash_index_update_or_next_insert 函数里面

 

问题

插入array的时候两次调用了hash查找是否重复了,zend_fetch_dimension_address_inner里面zend_hash_index_find有没有必要?(存在查找到key值就不再进行插入的情况?)


参考 http://www.laruence.com/2011/12/30/2435.html


原创粉丝点击