php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67965 Regression: stream_select blocks when using tls
Submitted: 2014-09-05 10:28 UTC Modified: 2014-09-09 16:37 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: arjen at react dot com Assigned: rdlowrey (profile)
Status: Closed Package: Streams related
PHP Version: 5.5Git-2014-09-05 (Git) OS: Linux
Private report: No CVE-ID: None
 [2014-09-05 10:28 UTC] arjen at react dot com
Description:
------------
stream_select blocks if there is still data in the read buffer which you haven't read yet..

Testscripts reads 8096 bytes (default chunksize) but there's already more to read. We expect stream_select to return $read again but it won't.

This works fine in 5.5.16 and previous versions.

Broken by https://github.com/php/php-src/commit/32be79dcfa1bc5af8682d9f512da68c5b3e2cbf3

https://bugs.php.net/bug.php?id=65137

Btw, tested using PHP5.5.16RC1 from http://downloads.php.net/jpauli/php-5.5.17RC1.tar.gz

Test script:
---------------
<?php

$host = 'tcp://php.net:443';
$chunkSize = 8192;

$fp = stream_socket_client($host, $errNumber, $errString, 5, STREAM_CLIENT_CONNECT);

stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);

$data = "GET / HTTP/1.1\r\nConnection: close\r\nHost: php.net\r\n\r\n";

fwrite($fp, $data);

while (!feof($fp))
{
	$read = array($fp);
	$except = $write = null;

	$changed = stream_select($read, $write, $except, 5, 0);

	if (!empty($read))
	{
		$read = fread($fp, $chunkSize);
		echo 'read ' . strlen($read) . PHP_EOL;
	}
}

Expected result:
----------------
read 8192
read 8192
read 8192
read 5961

Actual result:
--------------
read 8192
read 8192

and script hangs..

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-09-09 16:37 UTC] rdlowrey@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: rdlowrey
 [2014-09-09 16:37 UTC] rdlowrey@php.net
This should be fixed in commit f86b2193a:

https://github.com/php/php-src/commit/f86b2193a483f56b0bd056570a0cdb57ebe66e2f

Thanks for the report. If your issues persist (hopefully the won't) please update this issue :)
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Jul 21 17:01:27 2019 UTC