Press "Enter" to skip to content

A Patch for PHP 5.2.* to Prevent Hash-Collision Denial-of-Service Attacks

Since the official dev group won't ship PHP 5.2.18 for the hash-collision DoS (CVE-2011-4885) but many are still on 5.2, I backported dmitry's 5.4 patch (max_input_vars) to 5.2. For 5.3, upgrade to 5.3.9. On Windows or where patching is hard, lowering max_input_time helps. Limiting post_size is only a stopgap for other languages.

Filed in English, PHP应用, PHP源码分析
with 0 Comment

A PHP Array Hash-Collision Example

In the previous article I described how hash collisions can be used to mount DoS attacks against many languages (PHP, Java, Ruby, etc.) but gave no concrete example. Here, translated from nikic's 'Supercolliding a PHP array', is one: inserting 65536 specially constructed keys into a PHP array takes 30+ seconds versus 0.1 seconds for ordinary keys. Every insertion collides, so the array's underlying hash table degenerates into a linked list and the total traversals become O(n^2). Laruence then explains how the keys are built — for numeric keys the hash is index & tableMask, hashtable sizes are powers of two, so keys 0, 64, 128, 192... all hash to bucket 0.

Filed in English, PHP应用, 转载, 随笔
with 0 Comment

PHP Internals — A Few Hard-to-Understand Points in Zend Memory Management

A deep dive into zend_alloc: how Zend MM splits memory into small vs large blocks, the small-block free_buckets pointer-packing trick (ZEND_MM_SMALL_FREE_BUCKET), and the large_free_buckets key-tree (indexed by the high bit of the size via bsr) with bitmap-assisted best-fit search. Written because existing references — including TIPI — got it wrong.

Filed in English, PHP应用, PHP源码分析
with 0 Comment