Bug #65166 [Opn->Csd]: PHP Generator yield causing zend_mm_heap corrupted
Edit report at https://bugs.php.net/bug.php?id=65166&edit=1
ID: 65166
Updated by: nikic@php.net
Reported by: gavroche dot bull at gmail dot com
Summary: PHP Generator yield causing zend_mm_heap corrupted
-Status: Open
+Status: Closed
Type: Bug
Package: Unknown/Other Function
PHP Version: master-Git-2013-06-29 (Git)
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
This is probably the same as https://bugs.php.net/bug.php?id=66671, so was
fixed on the side of the mongodb extension.
Previous Comments:
------------------------------------------------------------------------
[2014-03-01 17:51:46] samo dot bracic at gmail dot com
This works:
-------------------------------
function dump($cursor, $chunk = 500)
{
$count = 0;
$output = [];
foreach ($cursor as $doc) {
$doc = array_filter($doc, function($v) { return !is_object($v); });
$output[] = $doc;
$count++;
if ($count === $chunk) {
yield json_encode($output);
$output = [];
$count = 0;
}
}
yield json_encode($output);
}
$m = new MongoClient();
$db = $m->dbname;
$collection = $db->selectCollection('collectionname');
$cursor = $collection->find();
foreach(dump($cursor) as $dump) {
var_dump($dump);
}
------------------------------------------------------------------------
[2013-06-30 00:49:07] gavroche dot bull at gmail dot com
And no, I have not been able to reproduce the bug without mongo db.
------------------------------------------------------------------------
[2013-06-29 22:32:24] gavroche dot bull at gmail dot com
Actually after investigation more, this code alone does not produce the error. But
it now seems that having too much lines of code in the script will produce this
error or a segmentation fault error.
For example, if I remove unused lines of code, the code execute properly. If I
change those unused lines of code for other lines like "null;", the error appears
again.
------------------------------------------------------------------------
[2013-06-29 22:18:03] nikic@php.net
Is it possible to reproduce this crash without the use of mongo db?
If not, it would be nice to have a backtrace for this (as described on https://bugs.php.net/bugs-generating-backtrace.php).
------------------------------------------------------------------------
[2013-06-29 21:59:27] gavroche dot bull at gmail dot com
Description:
------------
The yield function in the example below gives a "zend_mm_heap corrupted" error.
Test script:
---------------
function dump($chunk = 500)
{
$m = new MongoClient();
$db = $m->dbname;
$collection = $db->selectCollection('collectionname');
$cursor = $collection->find();
$count = 0;
$output = [];
foreach ($cursor as $doc) {
$doc = array_filter($doc, function($v) { return !is_object($v); });
$output[] = $doc;
$count++;
if ($count === $chunk) {
yield json_encode($output);
$output = [];
$count = 0;
}
}
yield json_encode($output);
}
foreach(dump() as $dump) {
var_dump($dump);
}
Expected result:
----------------
No error.
Actual result:
--------------
zend_mm_heap corrupted
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65166&edit=1
Thread (6 messages)