php / php-src

The PHP Interpreter
https://www.php.net
Other
38.1k stars 7.74k forks source link

stream_select does not abort upon exception or empty valid fd set #9590

Closed bwoebi closed 2 years ago

bwoebi commented 2 years ago

Description

The following code:

<?php

$fds = [];
for ($i = 0; $i < 1023; $i++) {
    $fds[] = fopen("/tmp/__0_a_evil_tmpfile.$i", 'w');
}

list($a, $b) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);

$r = [$a];
$w = $e = [];
var_dump(stream_select($r, $w, $e, PHP_INT_MAX));

Will result in a hang, after printing the warning, with an empty select() syscall being emitted.

However, adding in an error handler throwing an exception, e.g. set_error_handler(function() { throw new \Exception; }); at the start will cause the warning not be printed and still hang indefinitely, hiding the issue very well.

(Original bug report at https://github.com/amphp/amp/issues/398)

PHP Version

PHP 7.4 - master

Operating System

No response

arnaud-lb commented 2 years ago

Fixed in #9602