Bug #76901 [Com]: method_exists on SPL iterator passthrough method corrupts memory

From: Date: Wed, 19 Sep 2018 07:36:43 +0000
Subject: Bug #76901 [Com]: method_exists on SPL iterator passthrough method corrupts memory
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217135@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76901&edit=1 ID: 76901 Comment by: a at b dot c dot de Reported by: p dot bytniewski at neurosys dot com Summary: method_exists on SPL iterator passthrough method corrupts memory Status: Verified Type: Bug Package: SPL related Operating System: Linux - debian based PHP Version: 7.2.10 Assigned To: nikic Block user comment: N Private report: N New Comment: Also happens under Windows 10; except there is no fatal error reported; also affects $iterator->getSubPath(); garbage varies from run to run. With a slightly deeper directory tree: . └───directory ├───dir │ └───again │ ├───file3.txt │ ├───file4.txt │ └───file5.txt └───subdirectory ├───file1.txt └───file2.txt The result is: dir\again\file3.txt @1Gl\file4.txt subdirectory\file1.txt ` @l\file2.txt Previous Comments: ------------------------------------------------------------------------ [2018-09-19 06:14:33] p dot bytniewski at neurosys dot com Description: ------------ Having the following directory structure: ./directory ./directory/subdirectory ./directory/subdirectory/file2 ./directory/subdirectory/file1 when executing the provided test script, after encountering second file there seems to be some corruption. If there's no call to method_exists, everything works fine. Test script: --------------- <?php $path = 'directory'; $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS) ); foreach($iterator as $it) { if (!method_exists($iterator, 'getSubPathName')) { throw new \LogicException('This should never happen'); } echo $iterator->getSubPathName(). PHP_EOL; } Expected result: ---------------- subdirectory/file2 subdirectory/file1 Actual result: -------------- subdirectory/file2 pf��/file1 PHP Fatal error: Couldn't execute method RecursiveDirectoryIterator::next in Unknown on line 0 PHP Stack trace: PHP 1. {main}() path/to/file/iterator.php:0 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76901&edit=1

« previous php.bugs (#217135) next »