php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47997 stream_copy_to_stream returns 1 on empty streams
Submitted: 2009-04-16 23:52 UTC Modified: 2009-04-19 13:56 UTC
From: robots at shad dot pp dot ru Assigned:
Status: Closed Package: Streams related
PHP Version: 5.2.9 OS: *
Private report: No CVE-ID: None
 [2009-04-16 23:52 UTC] robots at shad dot pp dot ru
Description:
------------
Function returns 1 even if used to copy empty stream.

Reproduce code:
---------------
<?php

// Creating empty file
$src = fopen('srcfile.tmp', 'w+');
fclose($src);

$src = fopen('srcfile.tmp', 'r');
$dst = fopen('dstfile.tmp', 'w+');

echo stream_copy_to_stream($src, $dst);

fclose($src);
fclose($dst);

?>

Expected result:
----------------
0

Actual result:
--------------
1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-17 11:08 UTC] jani@php.net
From streams.c:

"in the event that the source file is 0 bytes, return 1 to indicate success because opening the file to write had already created a copy"

Looks like yet another design flaw in the streams API. 
 [2009-04-19 13:56 UTC] lbarnaud@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2012-02-25 10:58 UTC] odoucet@php.net
Automatic comment from SVN on behalf of odoucet
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=323498
Log: fix test file for bug #47997 : fopen(data://) requires allow_url_fopen=1
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC