stream_copy_to_stream() produces warning when source is not file
| Bug #50196 | stream_copy_to_stream() produces warning when source is not file | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2009-11-16 22:08 UTC | Modified: | 2009-12-19 01:13 UTC |
|
||||||||||
| From: | stas at zend dot com | Assigned: | ||||||||||||
| Status: | Closed | Package: | Streams related | |||||||||||
| PHP Version: | 5.2SVN-2009-11-16 (SVN) | OS: | win32 only | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2009-11-16 22:08 UTC] stas at zend dot com
Description:
------------
If I use stream_copy_to_stream with source stream being not file (say, HTTP socket) then I get this warning:
Warning: Invalid CRT parameters detected
This is because in _php_stream_copy_to_stream_ex() php_stream_stat() is applied to source stream, which goes to php_sockop_stat which calls fstat, which produces "invalid parameter" pseudo-exception.
Reproduce code:
---------------
$socket = open_http_socket();
$fp = fopen("data", "w");
stream_copy_to_stream($socket, $fp);
Actual result:
--------------
Warning: Invalid CRT parameters detected
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2009-11-17 17:42 UTC] stas@php.net
Is it really that hard to find a script that opens http socket in the manual? OK, here it goes: <?php $socket = fsockopen("localhost", 80, $errno, $errstr, 30); if (!$socket) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET / HTTP/1.1\r\n"; $out .= "Host: localhost\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($socket, $out); } $fp = fopen("data", "w"); stream_copy_to_stream($socket, $fp);[2009-12-19 01:13 UTC] stas@php.net