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)    
Subscription  


 [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

Comments

 [2006-07-12 09:52 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!