php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35849 [PATCH] stream_copy_to_stream() do strange behavior
Submitted: 2005-12-30 07:43 UTC Modified: 2008-07-21 01:00 UTC
From: sqchen at citiz dot net Assigned: wez (profile)
Status: No Feedback Package: Streams related
PHP Version: 5CVS-2005-12-30 (cvs) OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sqchen at citiz dot net
New email:
PHP Version: OS:

 

 [2005-12-30 07:43 UTC] sqchen at citiz dot net
Description:
------------
stream_copy_to_stream() do strange behavior when the maxlength parameter is negative, see the following codes:

Reproduce code:
---------------
<?php
$src   = fopen("1.txt", "r");  //"hell, world" in "1.txt"
$dest1 = fopen("des1.txt", "w");
$dest2 = fopen("des2.txt", "w");

/*----seg1------*/
stream_copy_to_stream($src, $des1, -2);
readfile("des1.txt");   //hello, world
stream_copy_to_stream($src, $des1);
readfile("des2.txt");   //nothing? why?


/* please compare it with seg2*/

/*----seg2-------*/
stream_copy_to_stream($src, $des1, 2);
readfile("des1.txt");   //he
stream_copy_to_stream($src, $des1);
readfile("des2.txt");   //hello, world
?>



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-30 08:25 UTC] sqchen at citiz dot net
SORRY, I have make a mistake on the code above, Below is the right code


Description:
------------
stream_copy_to_stream() do strange behavior when the maxlength parameter
is negative, see the following codes:

Reproduce code:
---------------
<?php
$src   = fopen("1.txt", "r");  //"hell, world" in "1.txt"
$dest1 = fopen("des1.txt", "w");
$dest2 = fopen("des2.txt", "w");

/*----seg1------*/
stream_copy_to_stream($src, $des1, -2);
readfile("des1.txt");   //hello, world
stream_copy_to_stream($src, $des2);
readfile("des2.txt");   //nothing? why?

/* please compare it with seg2*/

/*----seg2-------*/
stream_copy_to_stream($src, $des1, 2);
readfile("des1.txt");   //he
stream_copy_to_stream($src, $des2);
readfile("des2.txt");   //hello, world
?>
 [2005-12-30 13:32 UTC] nlopess@php.net
I can see two bugs in this report:
 * mmap()'ed fds aren't seeked() to update the position
 * the length is a size_t, where it should be a ssize_t, because PHP_STREAM_COPY_ALL is defined to -1

my patch: http://mega.ist.utl.pt/~ncpl/php_stream_mmap.txt
it makes all negative values to read all the file (to be consistent with non-mmap'ed fds).

I can also see some long/size_t/ssize_t mixes, which can be problematic in some platforms.
 [2005-12-30 14:52 UTC] sniper@php.net
Assigned to the streams maintainer.
 [2006-05-29 09:14 UTC] eddi at ai000 dot de
stream_copy_to_stream() does not copy from sockets

$s=stream_socket_server('tcp://127.0.0.1:1100',$er,$es);
while($c=stream_socket_accept($s,200)){
	$dat=fopen('text.txt','w');
	stream_copy_to_stream($c,$dat);
}

PHP 5.1.4 (cli)
GNU/Linux 2.6.16.18
 [2008-07-21 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC