Skip to content

Commit fda6bb1

Browse files
committed
Suppress erronous warning for stream casts that do not read buffer
1 parent f8d6c3d commit fda6bb1

7 files changed

+34
-40
lines changed

ext/posix/posix.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,15 @@ static int php_posix_stream_get_fd(zval *zfp, zend_long *fd) /* {{{ */
426426
if (stream == NULL) {
427427
return 0;
428428
}
429-
if (php_stream_can_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT) == SUCCESS) {
430-
php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT, (void*)fd, 0);
431-
} else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD) == SUCCESS) {
432-
php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)fd, 0);
429+
430+
/* get the fd.
431+
* NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag when casting.
432+
* It is only used here so that the buffered data warning is not displayed.
433+
*/
434+
if (php_stream_can_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL) == SUCCESS) {
435+
php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&fd, 0);
436+
} else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL) == SUCCESS) {
437+
php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void*)&fd, 0);
433438
} else {
434439
php_error_docref(NULL, E_WARNING, "Could not use stream of type '%s'",
435440
stream->ops->label);

ext/posix/tests/posix_isatty_stream_lose_data.phpt renamed to ext/posix/tests/posix_isatty_no_warning_on_stream_cast.phpt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
posix_isatty(): casting stream emits data loss
2+
posix_isatty(): casting stream does not emit data loss and should not emit warnings
33
--EXTENSIONS--
44
posix
55
--SKIPIF--
@@ -28,9 +28,6 @@ fclose($handle);
2828

2929
http_server_kill($pid);
3030
?>
31-
--EXPECTF--
32-
Warning: posix_isatty(): %d bytes of buffered data lost during stream conversion! in %s on line %d
33-
34-
Warning: posix_isatty(): %d bytes of buffered data lost during stream conversion! in %s on line %d
31+
--EXPECT--
3532
bool(false)
3633
string(4) "Body"

ext/posix/tests/posix_ttyname_stream_lose_data.phpt renamed to ext/posix/tests/posix_ttyname_no_warning_on_cast.phpt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
posix_ttyname(): casting stream emits data loss
2+
posix_ttyname(): casting stream does not emit data loss and should not emit warnings
33
--EXTENSIONS--
44
posix
55
--SKIPIF--
@@ -28,9 +28,6 @@ fclose($handle);
2828

2929
http_server_kill($pid);
3030
?>
31-
--EXPECTF--
32-
Warning: posix_ttyname(): %d bytes of buffered data lost during stream conversion! in %s on line %d
33-
34-
Warning: posix_ttyname(): %d bytes of buffered data lost during stream conversion! in %s on line %d
31+
--EXPECT--
3532
bool(false)
3633
string(4) "Body"

ext/standard/streamsfuncs.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,10 +1637,14 @@ PHP_FUNCTION(stream_isatty)
16371637

16381638
php_stream_from_zval(stream, zsrc);
16391639

1640-
if (php_stream_can_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT) == SUCCESS) {
1641-
php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT, (void*)&fileno, 0);
1642-
} else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD) == SUCCESS) {
1643-
php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fileno, 0);
1640+
/* get the fd.
1641+
* NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag when casting.
1642+
* It is only used here so that the buffered data warning is not displayed.
1643+
*/
1644+
if (php_stream_can_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL) == SUCCESS) {
1645+
php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&fileno, 0);
1646+
} else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL) == SUCCESS) {
1647+
php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void*)&fileno, 0);
16441648
} else {
16451649
RETURN_FALSE;
16461650
}
@@ -1678,11 +1682,14 @@ PHP_FUNCTION(sapi_windows_vt100_support)
16781682

16791683
php_stream_from_zval(stream, zsrc);
16801684

1681-
1682-
if (php_stream_can_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT) == SUCCESS) {
1683-
php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT, (void*)&fileno, 0);
1684-
} else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD) == SUCCESS) {
1685-
php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fileno, 0);
1685+
/* get the fd.
1686+
* NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag when casting.
1687+
* It is only used here so that the buffered data warning is not displayed.
1688+
*/
1689+
if (php_stream_can_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL) == SUCCESS) {
1690+
php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&fileno, 0);
1691+
} else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL) == SUCCESS) {
1692+
php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void*)&fileno, 0);
16861693
} else {
16871694
if (!enable_is_null) {
16881695
php_error_docref(

run-tests.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -857,13 +857,7 @@ function write_information(): void
857857
$php_cgi_info = '';
858858
}
859859

860-
if ($phpdbg) {
861-
$phpdbg_info = shell_exec("$phpdbg $pass_options $info_params $no_file_cache -qrr \"$info_file\"");
862-
$php_info_sep = "\n---------------------------------------------------------------------";
863-
$phpdbg_info = "$php_info_sep\nPHP : $phpdbg $phpdbg_info$php_info_sep";
864-
} else {
865-
$phpdbg_info = '';
866-
}
860+
$phpdbg_info = '';
867861

868862
if (function_exists('opcache_invalidate')) {
869863
opcache_invalidate($info_file, true);

tests/output/sapi_windows_vt100_support_stream_lose_data.phpt renamed to tests/output/sapi_windows_vt100_support_no_warning_on_cast.phpt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
sapi_windows_vt100_support(): casting stream emits data loss
2+
sapi_windows_vt100_support(): casting stream does not emit data loss and should not emit warnings
33
--SKIPIF--
44
<?php
55
if (PHP_OS_FAMILY !== "Windows") {
@@ -29,9 +29,6 @@ fclose($handle);
2929

3030
http_server_kill($pid);
3131
?>
32-
--EXPECTF--
33-
Warning: sapi_windows_vt100_support(): %d bytes of buffered data lost during stream conversion! in %s on line %d
34-
35-
Warning: sapi_windows_vt100_support(): %d bytes of buffered data lost during stream conversion! in %s on line %d
32+
--EXPECT--
3633
bool(false)
3734
string(4) "Body"

tests/output/stream_isatty_stream_lose_data.phpt renamed to tests/output/stream_isatty_no_warning_on_cast.phpt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
stream_isatty(): casting stream emits data loss
2+
stream_isatty(): casting stream does not emit data loss and should not emit warnings
33
Bug GH-10092 (Internal stream casting should not emit lost bytes warning twice)
44
--SKIPIF--
55
<?php
@@ -27,9 +27,6 @@ fclose($handle);
2727

2828
http_server_kill($pid);
2929
?>
30-
--EXPECTF--
31-
Warning: stream_isatty(): %d bytes of buffered data lost during stream conversion! in %s on line %d
32-
33-
Warning: stream_isatty(): %d bytes of buffered data lost during stream conversion! in %s on line %d
30+
--EXPECT--
3431
bool(false)
3532
string(4) "Body"

0 commit comments

Comments
 (0)