|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74090 stream_get_contents maxlength>-1 returns empty string on windows
Submitted: 2017-02-13 05:05 UTC Modified: 2017-02-13 16:54 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: me at micksam7 dot com Assigned:
Status: Closed Package: Streams related
PHP Version: 7.1.1 OS: Windows 10 v1607
Private report: No CVE-ID: None
 [2017-02-13 05:05 UTC] me at micksam7 dot com
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://", $errno, $errstr, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);
stream_set_blocking($fd, 0);
var_dump(stream_get_contents($fd,65565)); //Does not work
var_dump(stream_get_contents($fd));       //No maxlength, works fine

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) "<>"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-13 07:56 UTC]
-Status: Open +Status: Feedback
 [2017-02-13 07:56 UTC]
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.

 [2017-02-13 08:02 UTC]
-Status: Feedback +Status: Verified
 [2017-02-13 08:02 UTC]
Ah, err, to few coffee in the morning. The exact actual result, so verified.

 [2017-02-13 11:47 UTC]
-Status: Verified +Status: Feedback
 [2017-02-13 11:47 UTC]
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.

 [2017-02-13 16:54 UTC] me at micksam7 dot com
-Status: Feedback +Status: Open
 [2017-02-13 16:54 UTC] me at micksam7 dot com
stream_socket_recvfrom() seems to work just fine in this case

I submitted this bug after tracking down a problem with reactphp's dns resolver which uses a generic socket class and tracked it down to this function not behaving correctly on Windows. I've already reported it to reactphp and offered a few workarounds, but figured I should still submit this report given this function behaves differently between *nix and Windows with maxlength set.
 [2017-02-15 13:52 UTC]
Automatic comment on behalf of ab
Log: Fixed bug #74090 stream_get_contents maxlength&gt;-1 returns empty string
 [2017-02-15 13:52 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 12:01:28 2024 UTC