ID:               49896
 Updated by:       [email protected]
 Reported By:      jmy at morgontech dot com
-Status:           Open
+Status:           Verified
-Bug Type:         Arrays related
+Bug Type:         Reproducible crash
 Operating System: CentOS 5.3 / Kernel 2.6.18-128
-PHP Version:      5.3.0
+PHP Version:      5.*, 6 (2009-10-19


Previous Comments:
------------------------------------------------------------------------

[2009-10-16 08:24:35] jmy at morgontech dot com

Description:
------------
In an attempt to cull some unneeded array elements from within a
user-defined function for uksort(), I came across a very odd memory
exhaustion issue where array.c collapses under a sudden 1.5GB memory
allocation attempt.

I realize this may not be the best way to accomplish my goal, but am
pretty sure the memory exhaustion shouldn't be happening, regardless.

Reproduce code:
---------------
<?php
$sortOrder = Array(281, 830, 580, 541, 838, 839, 702, 625, 102, 234,
532, 317, 859, 738, 17, 350);
$myArray = Array(
    830 => 'eightthirty',
    317 => 'threeseventeen',
    102 => 'oneohtwo',
    281 => 'twoeightyone',
    14  => 'fourteen',
    580 => 'fiveeighty',
    541 => 'fivefourtyone',
    350 => 'threefifty',
    838 => 'eightthirtyeight',
    839 => 'eightthirtynine',
    702 => 'sevenohtwo',
    625 => 'sixtwentyfive',
    234 => 'twothreefour',
    532 => 'fivethirtytwo',
    859 => 'eightfiftynine',
    738 => 'seventhirtyeight',
    17  => 'seventeen'
);  

    function sortByOrder($a, $b) {
        global $sortOrder;
        global $myArray;

        if (!in_array($a, $sortOrder)) {
            unset($myArray[$a]);
            return 1;
        }
        if (!in_array($b, $sortOrder)) {
            return -1;
        }

        return array_search($a, $sortOrder) - array_search($b,
$sortOrder);
    }

uksort($myArray, 'sortByOrder');
print_r($myArray);
?>

Expected result:
----------------
Expected result is an array sorted to match $sortOrder

Actual result:
--------------
Fatal error: Allowed memory size of 16777216 bytes exhausted at
/root/source/php-5.3.0/ext/standard/array.c:694 (tried to allocate
1515870810 bytes) in /path/to/uksort_memory.php on line 38


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49896&edit=1

Reply via email to