Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.1.4

Bug #8103 Length parameter must be greater than 0 on empty files
Submitted: 2006-07-02 23:55 UTC
From: roychri at php dot net Assigned: techtonik
Status: Closed Package: File_SearchReplace (version 1.1.0)
PHP Version: 4.3.11 OS: Mandrake Linux release 8.2 (Blue
Roadmaps: (Not assigned)    

 [2006-07-02 23:55 UTC] roychri at php dot net (Christian Roy)
Description: ------------ When using the preg search function on files which are empty, I get an error message: fread(): Length parameter must be greater than 0. The pregSearch() function is using fopen and filesize and fread to open the file to search in. However, since the file is empty, fread gets 0 as second parameter and generate that warning. I do not think the function pregSearch() should open and search an empty file. I was able to get rid of the error by making this change (in patch format): --- /usr/local/lib/php/File/SearchReplace.php~ Sun Jul 2 11:31:09 2006 +++ /usr/local/lib/php/File/SearchReplace.php Sun Jul 2 16:52:16 2006 @@ -367,7 +367,12 @@ clearstatcache(); - $file = fread($fp = fopen($filename, 'r'), filesize($filename)); fclose($fp); + $size = filesize($filename); + if ( empty($size) ) { + return FALSE; + } + $file = fread($fp = fopen($filename, 'r'), $size); + fclose($fp); $local_find = array_values((array) $this->find); $local_replace = (is_array($this->replace)) ? array_values($this->replace) : $this->replace; Let me know if you have any questions. Test script: --------------- $files = Array("/tmp/test/nonemptyfile", "/tmp/test/emptyfile"); $from = "/foo/"; $to = "bar"; $snr = new File_SearchReplace( $from, $to, $files); $snr->setSearchFunction("preg"); $snr->doSearch(); print "DONE\n"; Expected result: ---------------- DONE Actual result: -------------- Warning: fread(): Length parameter must be greater than 0. in /usr/local/lib/php/File/SearchReplace.php on line 370 DONE


 [2006-07-12 09:52 UTC] techtonik (anatoly techtonik)
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at Fixed! =)