Bug #74090 [Ver->Fbk]: stream_get_contents maxlength>-1 returns empty string on windows
| From: | ab@php.net | Date: | Mon, 13 Feb 2017 11:47:41 +0000 |
| Subject: | Bug #74090 [Ver->Fbk]: stream_get_contents maxlength>-1 returns empty string on windows | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-207369@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74090&edit=1
ID: 74090
Updated by: ab@php.net
Reported by: me at micksam7 dot com
Summary: stream_get_contents maxlength>-1 returns empty
string on windows
-Status: Verified
+Status: Feedback
Type: Bug
Package: Streams related
Operating System: Windows 10 v1607
PHP Version: 7.1.1
Block user comment: N
Private report: N
New Comment:
Btw. question - why don't you use stream_socket_recvfrom()? The reason to fail here is a
possible bug in the stream liveness check, need further tests.
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2017-02-13 08:02:05] ab@php.net
Ah, err, to few coffee in the morning. The exact actual result, so verified.
Thanks.
------------------------------------------------------------------------
[2017-02-13 07:56:25] ab@php.net
Thanks for the report. I'm not reproducing this, here 7.0 through master
string(0) ""
string(45) "Ö�� ⺠⺠exampleâ¥org ⺠âºï¿½â
⺠⺠J� â¦]��""
Either it's some environment issue, or indeed some more investigation is needed.
Thanks.
------------------------------------------------------------------------
[2017-02-13 05:05:04] me at micksam7 dot com
Description:
------------
stream_get_contents() with any maxlength greater than -1 returns an empty string,
This only appears to occur with UDP streams opened via stream_socket_client(), specifically on
Windows 10.
This problem doesn't occur on Linux and may function fine on older versions of Windows.
The problem appears to reside somewhere in the php_stream_eof call within _php_stream_copy_to_mem -
php_stream_eof seems to always return true on UDP streams on Windows 10 systems. More digging
required.
Test script:
---------------
//Submit DNS Request
$data = base64_decode("1oIBAAABAAAAAAAAB2V4YW1wbGUDb3JnAAABAAE=");
$fd = stream_socket_client("udp://8.8.8.8:53", $errno, $errstr, 0, STREAM_CLIENT_CONNECT |
STREAM_CLIENT_ASYNC_CONNECT);
stream_set_blocking($fd, 0);
stream_socket_sendto($fd,$data);
sleep(1);
var_dump(stream_get_contents($fd,65565)); //Does not work
var_dump(stream_get_contents($fd)); //No maxlength, works fine
stream_socket_shutdown($fd,STREAM_SHUT_RDWR);
Expected result:
----------------
Returns a valid DNS response roughly 45 bytes long, then an empty string.
string(45) "<>"
string(0) ""
Actual result:
--------------
Returns an empty string, then a valid DNS response.
string(0) ""
string(45) "<>"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74090&edit=1