Bug in iter\chain or PHP.
SamMousa opened this issue · 4 comments
Possibly related to: https://bugs.php.net/bug.php?id=69599
(I'm assuming the nikic there is you)
I have a generator.
I can dump it using iterator_to_array()
:
array(1) { [2]=> string(6) "test123" }
When I chain it: iterator_to_array(\iter\chain(['a' => 'b'], $iter)
I get:
Segmentation fault (core dumped)
I can't reproduce this using simple arrays or generators.
I feel it is related to some kind of garbage collection:
The source generator has this code:
public function filter(Authorizable $source, iterable $targets, string $permission)
{
foreach($targets as $key => $target) {
if ($this->isAllowed($source, $target, $permission)) {
yield $key => $target;
$result[$key] = $target;
}
}
}
Note the $result
is unused; but by adding it intermittently works.
I'd be open to any help in reproducing this / helping debug this.
What version of PHP are you using? Can you run your code through USE_ZEND_ALLOC=0 valgrind php [args]
and provide the result?
PHP 7.1.2 (cli) (built: Feb 20 2017 19:01:09) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
Valgrind:
==201== Memcheck, a memory error detector
==201== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==201== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==201== Command: php -S 0.0.0.0:80 -t public/
==201== Parent PID: 182
==201==
==201== Invalid free() / delete / delete[] / realloc()
==201== at 0x4C92A6E: free (vg_replace_malloc.c:530)
==201== by 0x40573A6: ??? (in /lib/ld-musl-x86_64.so.1)
==201== Address 0x4e9a180 is in a rw- mapped file /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so segment
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x4EC81CF: ???
==201== by 0x1FA: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x2F63696C6275702E: ???
==201== by 0x68702E7865646E68: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x746E652F6372732E: ???
==201== by 0x6131366632363832: ???
==201== by 0x3964636630323860: ???
==201== by 0x6535663735663931: ???
==201== by 0x6537316261366360: ???
==201== by 0x3330636233633465: ???
==201== by 0x3232613435373337: ???
==201== by 0x2561633763656561: ???
==201== by 0x3725413325324132: ???
==201== by 0x3325304133256941: ???
==201== by 0x3325384133257341: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x6E65762F6372732E: ???
==201== by 0x6F7475612F726F63: ???
==201== by 0x7068702E64616F6B: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x6E65762F6372732E: ???
==201== by 0x706D6F632F726F63: ???
==201== by 0x7475612F7265736E: ???
==201== by 0x65725F64616F6C6E: ???
==201== by 0x561AF8: __zend_malloc (in /usr/local/bin/php)
==201== by 0xB83A13F: ???
==201== by 0x1101: ???
==201== by 0x3804AAD1: vgMemCheck_new_block (mc_malloc_wrappers.c:378)
==201== by 0x37: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x6E65762F6372732E: ???
==201== by 0x706D6F632F726F63: ???
==201== by 0x616C432F7265736E: ???
==201== by 0x726564616F4C7372: ???
==201== by 0xFFF: ???
==201== by 0x7: ???
==201== by 0x5981974D: ???
==201== by 0x2E845FC5: ???
==201== by 0x59084296: ???
==201== by 0x92EBCD1: ??? (in /usr/lib/libicudata.so.57.1)
==201== by 0x59085CDE: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x6E65762F6372732E: ???
==201== by 0x61797A652F726F63: ???
==201== by 0x706C6D74682F676D: ???
==201== by 0x2F72656966697274: ???
==201== by 0x2F7972617262696B: ???
==201== by 0x697275504C4D5447: ???
==201== by 0x6D6F632E72656965: ???
==201== by 0x68702E7265736F6F: ???
==201== by 0x5678FE: ??? (in /usr/local/bin/php)
==201== by 0x5685D8: ??? (in /usr/local/bin/php)
==201== by 0x56D1D9: ??? (in /usr/local/bin/php)
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x6E65762F6372732E: ???
==201== by 0x7A7A75672F726F63: ???
==201== by 0x702F70747468656B: ???
==201== by 0x2F6372732F377272: ???
==201== by 0x6E6F6974636E7565: ???
==201== by 0x64756C636E695F72: ???
==201== by 0x6D6F632E72656965: ???
==201== by 0x68702E7265736F6F: ???
==201== by 0x56006F: ??? (in /usr/local/bin/php)
==201== by 0x5: ???
==201== by 0xB8919EF: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x6E65762F6372732E: ???
==201== by 0x666D79732F726F63: ???
==201== by 0x796C6F702F796E6E: ???
==201== by 0x73626D2D6C6C6965: ???
==201== by 0x6F622F676E697273: ???
==201== by 0x2E7061727473746E: ???
==201== by 0x68702E656475006F: ???
==201== by 0x68702E726573006F: ???
==201== by 0x56006F: ??? (in /usr/local/bin/php)
==201== by 0x5: ???
==201== by 0xB8919EF: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x6E65762F6372732E: ???
==201== by 0x666977732F726F63: ???
==201== by 0x2F72656C69616D73: ???
==201== by 0x69616D7466697772: ???
==201== by 0x2F62696C2F72656B: ???
==201== by 0x65725F7466697772: ???
==201== by 0x702E646572697570: ???
==201== by 0x68702E726573006F: ???
==201== by 0x56006F: ??? (in /usr/local/bin/php)
==201== by 0x5: ???
==201== by 0xB8919EF: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x6E65762F6372732E: ???
==201== by 0x696B696E2F726F63: ???
==201== by 0x732F726574692F62: ???
==201== by 0x73746F6F622F6371: ???
==201== by 0x7068702E70617273: ???
==201== by 0x2F73657373616C62: ???
==201== by 0x68702E7466697752: ???
==201== by 0x68702E726500006F: ???
==201== by 0x56006F: ??? (in /usr/local/bin/php)
==201== by 0x5: ???
==201== by 0xB8919EF: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x6E65762F6372732E: ???
==201== by 0x736969792F726F63: ???
==201== by 0x326969792F74666E: ???
==201== by 0x696959657361422E: ???
==201== by 0x59085CDE: ???
==201== by 0x1E4BD8B9: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x2F6769666E6F632E: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x2F6769666E6F632E: ???
==201== by 0x702E6E6F6D6D6F62: ???
==201== by 0x588EEE: zend_stack_push (in /usr/local/bin/php)
==201== by 0x573F1E: ??? (in /usr/local/bin/php)
==201== by 0x57434A: ??? (in /usr/local/bin/php)
==201== by 0x575CE7: ??? (in /usr/local/bin/php)
==201== by 0x5767D6: ??? (in /usr/local/bin/php)
==201== by 0x575BE5: ??? (in /usr/local/bin/php)
==201== by 0x5767D6: ??? (in /usr/local/bin/php)
==201== by 0x575BE5: ??? (in /usr/local/bin/php)
==201== by 0x57759C: ??? (in /usr/local/bin/php)
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x6E65762F6372732E: ???
==201== by 0x736969792F726F63: ???
==201== by 0x657478652F74666E: ???
==201== by 0x702E736E6F69736D: ???
==201== by 0xD: ???
==201== by 0xBE59A8F: ???
==201== by 0xFFEFFB4F7: ???
==201== by 0xBFEA04F: ???
==201== by 0xEC2DFF: ???
==201== by 0x73: ???
==201== by 0x5678FE: ??? (in /usr/local/bin/php)
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x6D6F632F6372732E: ???
==201== by 0x2F73746E656E6F6F: ???
==201== by 0x7068702E72657354: ???
==201== by 0x4F: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x646F6D2F6372732E: ???
==201== by 0x726573552F736C64: ???
==201== by 0x6E65762F6372732E: ???
==201== by 0x736969792F726F63: ???
==201== by 0x326969792F74666E: ???
==201== by 0x502F67756265642C: ???
==201== by 0x7068702E6C656E60: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x646F6D2F6372732E: ???
==201== by 0x697463412F736C64: ???
==201== by 0x64726F6365526575: ???
==201== by 0x1101: ???
==201== by 0x3804AAD1: vgMemCheck_new_block (mc_malloc_wrappers.c:378)
==201== by 0x47: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x6E65762F6372732E: ???
==201== by 0x2D6D61732F726F63: ???
==201== by 0x2F636162612F7468: ???
==201== by 0x6E6E6F632F637272: ???
==201== by 0x792F73726F746364: ???
==201== by 0x697463412F326968: ???
==201== by 0x64726F6365526575: ???
==201== by 0x7A69726F68747540: ???
==201== by 0x69617254656C6260: ???
==201== by 0xC57D187: ???
==201== by 0x300000000F: ???
==201==
==201== Conditional jump or move depends on uninitialised value(s)
==201== at 0x404EE12: strlcpy (in /lib/ld-musl-x86_64.so.1)
==201== by 0x6575712F6372732E: ???
==201== by 0x7463412F73656971: ???
==201== by 0x7972657551657668: ???
==201== by 0x1: ???
==201== by 0x42731C: ??? (in /usr/local/bin/php)
==201== by 0x550BF7: compile_filename (in /usr/local/bin/php)
==201== by 0x4C937A2: realloc (vg_replace_malloc.c:785)
==201== by 0xFFEFFADCF: ???
==201== by 0xC7: ???
==201== by 0xFFEFFABD3: ???
==201== by 0x3: ???
==201==
==201==
==201== HEAP SUMMARY:
==201== in use at exit: 6,513,450 bytes in 40,571 blocks
==201== total heap usage: 93,090 allocs, 52,528 frees, 19,973,213 bytes allocated
==201==
==201== LEAK SUMMARY:
==201== definitely lost: 808 bytes in 6 blocks
==201== indirectly lost: 24 bytes in 1 blocks
==201== possibly lost: 2,546,148 bytes in 20,547 blocks
==201== still reachable: 3,966,470 bytes in 20,017 blocks
==201== suppressed: 0 bytes in 0 blocks
==201== Rerun with --leak-check=full to see details of leaked memory
==201==
==201== For counts of detected and suppressed errors, rerun with: -v
==201== Use --track-origins=yes to see where uninitialised values come from
==201== ERROR SUMMARY: 108 errors from 22 contexts (suppressed: 0 from 0)
Please try upgrading to a newer version of PHP 7.1. PHP 7.1.2 in particular had a major regression in generator stack frame allocation, which is likely the cause of this issue.
You were right, thnx.