php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42237 [PATCH] stream_copy_to_stream returns invalid values for memmapped streams
Submitted: 2007-08-07 20:24 UTC Modified: 2007-08-08 02:16 UTC
From: andrew dot minerd at sellingsource dot com Assigned:
Status: Closed Package: Streams related
PHP Version: 5.2.4RC1 OS: Gentoo
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: andrew dot minerd at sellingsource dot com
New email:
PHP Version: OS:

 

 [2007-08-07 20:24 UTC] andrew dot minerd at sellingsource dot com
Description:
------------
When copying from a memmapped stream, stream_copy_to_stream returns the length of the memory-mapped segment, regardless of how much data was actually written to the recipient stream.


Reproduce code:
---------------
<?php
class DummyWriteStream
{
	function stream_open($path, $mode, $options, &$opened_path) { return TRUE; }
	function stream_write($data) { return 0; }
}

stream_wrapper_register('test2', 'DummyWriteStream');

$fp1 = fopen('/etc/hosts', 'r');
$fp2 = fopen('test2://test', 'w');

var_dump(stream_copy_to_stream($fp1, $fp2, 8192));
?>

Expected result:
----------------
int(0)

Actual result:
--------------
int(1228)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-07 20:26 UTC] andrew dot minerd at sellingsource dot com
Patch:

--- streams.c   2007-01-15 09:07:07.000000000 -0800
+++ streams2.c  2007-08-07 13:23:14.000000000 -0700
@@ -1309,11 +1309,11 @@
                p = php_stream_mmap_range(src, php_stream_tell(src), maxlen, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped);
 
                if (p) {
-                       haveread = php_stream_write(dest, p, mapped);
+                       written = php_stream_write(dest, p, mapped);
 
                        php_stream_mmap_unmap(src);
 
-                       return mapped;
+                       return written;
                }
        }
 [2007-08-07 20:37 UTC] andrew dot minerd at sellingsource dot com
Erm, I changed haveread to written for clarity... obviously you'd have to define the variable, etc -- that was missing from my patch. :-p
 [2007-08-08 02:16 UTC] iliaa@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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC