Skip to content

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

Closed
@bwoebi

Description

@bwoebi

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 amphp/amp#398)

PHP Version

PHP 7.4 - master

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions