|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-04-28 07:38 UTC] mike at ziebeck dot net
Description: ------------ PHP crashes if phar archive is beeing recreated and used after it has been unlinked. Reproduce Steps: 1] create new phar archive (DataArchive0.phar) 2] add any file 3] unset phar object instance 4] unlink phar archive file (DataArchive0.phar) 6] create new phar archive (DataArchive0.phar) 7] add any file : crash As far as I can see: -------------------- * There's no difference between $p->addFromString() and adding via Stream wrapper using file_put_contents() * if stub is set before adding a file, PHP crashes here * if phar object instance is not unset + unlinking is denied + archive files stay alive + PHP does not crash * creating and unlinking lots(1024) of different archives before using the name of the first one again does not matter Using win32 snapshot version of PHP 5.2: [Problem persists] ----------------------------------------------------------- http://snaps.php.net/win32/php5.2-win32-200804280830.zip http://snaps.php.net/win32/pecl5.2-win32-200804280830.zip Using win32 snapshot version of PHP 5.3: [Problem persists] ----------------------------------------------------------- http://snaps.php.net/win32/php5.3-win32-200804251230.zip http://snaps.php.net/win32/pecl5.3-win32-200804251230.zip Reproduce code: --------------- <? $dirName=str_replace(DIRECTORY_SEPARATOR, "/", dirname(__FILE__)); $reuseDelay=1024; for($i=0; $i<2*$reuseDelay; $i++){ $pArchive="DataArchive".($i%$reuseDelay).".phar"; $p=new Phar($pPath="$dirName/$pArchive", 0, $pArchive); echo("\rFile($i) Name($pArchive) "); //$p->setStub('<? __HALT_COMPILER(); ? >'); $p->addFromString($i, ""); //file_put_contents("phar://$pPath/$i", ""); unset($p); unlink($pPath); } echo("\r Files written($i) \r\n"); ?> Expected result: ---------------- Files written(2048) Actual result: -------------- File(1024) Name(DataArchive0.phar) CLI crashes, Windows asks for report PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 02:00:01 2025 UTC |
OK, I have a working solution: static void phar_spl_foreign_dtor(spl_filesystem_object *object TSRMLS_DC) /* {{{ */ { phar_archive_data *phar_data = (phar_archive_data *) object->oth; --(phar_data->refcount); phar_archive_delref(phar_data TSRMLS_CC); object->oth = NULL; } /* }}} */ Unfortunately this will only work if SPL is enabled, so it won't always avoid that crash under PHP 5.2. Anyone have any better ideas?This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pecl.php.net. In case this was a pecl.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PECL better. OK, we couldn't use my idea because it would prevent caching, which would obviously slow down Web apps stored in phars to an unacceptable level. PHP no longer crashes with this code (i.e. unset() works), but if you want to unlink a phar fully before the end of the script you'll need to use a new phar-specific unlink method, Phar::unlinkArchive(). So in order to get the behaviour you want, your code would read: <?php $dirName=str_replace(DIRECTORY_SEPARATOR, "/", dirname(__FILE__)); $reuseDelay=1024; for($i=0; $i<2*$reuseDelay; $i++){ $pArchive="DataArchive".($i%$reuseDelay).".phar"; $p=new Phar($pPath="$dirName/$pArchive", 0, $pArchive); echo("\rFile($i) Name($pArchive) "); //$p->setStub('<? __HALT_COMPILER(); ? >'); $p->addFromString($i, ""); //file_put_contents("phar://$pPath/$i", ""); unset($p); //unlink($pPath); Phar::unlinkArchive($pPath); } echo("\r Files written($i) \r\n"); ?>