#42237 [Opn->Csd]: [PATCH] stream_copy_to_stream returns invalid values for memmapped streams

From: Date: Wed, 08 Aug 2007 02:16:48 +0000
Subject: #42237 [Opn->Csd]: [PATCH] stream_copy_to_stream returns invalid values for memmapped streams
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-115860@lists.php.net to get a copy of this message
ID: 42237 Updated by: iliaa@php.net Reported By: andrew dot minerd at sellingsource dot com -Status: Open +Status: Closed Bug Type: Streams related Operating System: Gentoo PHP Version: 5.2.4RC1 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2007-08-07 20:37:07] 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-07 20:26:00] 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:24:04] 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) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42237&edit=1

« previous php.bugs (#115860) next »