From:             
Operating system: all
PHP version:      5.3.8
Package:          Filesystem function related
Bug Type:         Bug
Bug description:fclose(), file_put_contents(), copy() do not return false 
properly

Description:
------------
The fclose() function does not check the result of flushing the stream:

        if (!stream->is_persistent) {
                zend_list_delete(stream->rsrc_id);
        } else {
                php_stream_pclose(stream);
        }

        RETURN_TRUE;

php_stream_pclose has a return value but it is ignored.

php_stream_pclose, in turn, calls _php_stream_free which flushes the stream
but 
does not check the return value either:

        /* make sure everything is saved */
        _php_stream_flush(stream, 1 TSRMLS_CC);

Contrary to the comment we did not make sure of anything (:

So the fix has to be made at least as deep as _php_stream_flush to be
effective. 
I have verified that _php_stream_flush does pay attention to the result of
the 
underlying flush operation. Note that fflush() reports write errors
successfully 
while fclose() doesn't).

In many environments, including stdio (plain old files), the final write to
disk 
might not sometimes occur until the stream is flushed by _php_stream_flush.
If 
this fails, for instance because the disk is full, PHP pays no heed to the

error.

This is especially obvious if you use a stream wrapper that does its actual

writing when the stream is closed (for instance storing an object with a
single 
HTTP request), but again, it could happen with normal files too.

Because of this deeper issue with _php_stream_free, all other PHP
convenience 
functions for files such as copy() and file_put_contents() also fail to 
correctly report false when the final flush of data to disk fails when
closing a 
file.

This has serious consequences for any application that is counting on data

integrity, which would be pretty much every application that uses files I
guess.



-- 
Edit bug report at https://bugs.php.net/bug.php?id=60110&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=60110&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=60110&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=60110&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=60110&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=60110&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=60110&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=60110&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=60110&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=60110&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=60110&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=60110&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=60110&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=60110&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=60110&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=60110&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=60110&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=60110&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=60110&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=60110&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=60110&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=60110&r=mysqlcfg

Reply via email to