Skip to content

Commit ae75542

Browse files
committed
Fix #79805: sapi_windows_vt100_support throws TypeError
It does not make sense to throw a `TypeError` when the stream can't be analyzed. If `sapi_windows_vt100_support()` is used as getter, we just return `false` in that case; if the function is used as setter, we additionally trigger a warning. We also fix the test cases for this function, which have been broken before. Note that these tests are still whitespace sensitive.
1 parent 4659c12 commit ae75542

16 files changed

+266
-674
lines changed

ext/standard/basic_functions.stub.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ function stream_isatty($stream): bool {}
13141314

13151315
#ifdef PHP_WIN32
13161316
/** @param resource $stream */
1317-
function sapi_windows_vt100_support($stream, bool $enable = UNKNOWN): bool {}
1317+
function sapi_windows_vt100_support($stream, ?bool $enable = null): bool {}
13181318
#endif
13191319

13201320
/** @param resource $stream */

ext/standard/basic_functions_arginfo.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 05b740207a70a9d272b4c327882fd0b52016a0af */
2+
* Stub hash: 49142ce7a3c79618e87a350b87994e01b1d69ff8 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
55
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
@@ -2028,7 +2028,7 @@ ZEND_END_ARG_INFO()
20282028
#if defined(PHP_WIN32)
20292029
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sapi_windows_vt100_support, 0, 1, _IS_BOOL, 0)
20302030
ZEND_ARG_INFO(0, stream)
2031-
ZEND_ARG_TYPE_INFO(0, enable, _IS_BOOL, 0)
2031+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, enable, _IS_BOOL, 1, "null")
20322032
ZEND_END_ARG_INFO()
20332033
#endif
20342034

ext/standard/streamsfuncs.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -1623,15 +1623,13 @@ PHP_FUNCTION(sapi_windows_vt100_support)
16231623
{
16241624
zval *zsrc;
16251625
php_stream *stream;
1626-
zend_bool enable;
1626+
zend_bool enable, enable_is_null = 1;
16271627
zend_long fileno;
16281628

1629-
int argc = ZEND_NUM_ARGS();
1630-
16311629
ZEND_PARSE_PARAMETERS_START(1, 2)
16321630
Z_PARAM_RESOURCE(zsrc)
16331631
Z_PARAM_OPTIONAL
1634-
Z_PARAM_BOOL(enable)
1632+
Z_PARAM_BOOL_OR_NULL(enable, enable_is_null)
16351633
ZEND_PARSE_PARAMETERS_END();
16361634

16371635
php_stream_from_zval(stream, zsrc);
@@ -1643,19 +1641,22 @@ PHP_FUNCTION(sapi_windows_vt100_support)
16431641
php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fileno, 0);
16441642
}
16451643
else {
1646-
zend_type_error(
1647-
"%s() was not able to analyze the specified stream",
1648-
get_active_function_name()
1649-
);
1650-
RETURN_THROWS();
1644+
if (!enable_is_null) {
1645+
php_error_docref(
1646+
NULL,
1647+
E_WARNING,
1648+
"not able to analyze the specified stream"
1649+
);
1650+
}
1651+
RETURN_FALSE;
16511652
}
16521653

16531654
/* Check if the file descriptor is a console */
16541655
if (!php_win32_console_fileno_is_console(fileno)) {
16551656
RETURN_FALSE;
16561657
}
16571658

1658-
if (argc == 1) {
1659+
if (enable_is_null) {
16591660
/* Check if the Windows standard handle has VT100 control codes enabled */
16601661
if (php_win32_console_fileno_has_vt100(fileno)) {
16611662
RETURN_TRUE;

tests/output/sapi_windows_vt100_support.inc

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ function testToStdOut()
3535
'STDERR (constant)' => STDERR,
3636
'STDERR (fopen)' => fopen('php://stderr', 'wb'),
3737
'STDERR (php://fd/2)' => fopen('php://fd/2', 'wb'),
38-
'Not a stream' => 'foo',
3938
'Invalid stream (php://temp)' => fopen('php://temp', 'wb'),
4039
'Invalid stream (php://input)' => fopen('php://input', 'wb'),
4140
'Invalid stream (php://memory)' => fopen('php://memory', 'wb'),

tests/output/sapi_windows_vt100_support_winko_err.phpt

+21-55
Original file line numberDiff line numberDiff line change
@@ -76,70 +76,36 @@ STDERR (php://fd/2):
7676
- current value : bool(false)
7777
- disabling VT100: bool(false)
7878
- current value : bool(false)
79-
Not a stream:
80-
- current value :
81-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
82-
bool(false)
83-
- enabling VT100 :
84-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
85-
bool(false)
86-
- current value :
87-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
88-
bool(false)
89-
- disabling VT100:
90-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
91-
bool(false)
92-
- current value :
93-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
94-
bool(false)
9579
Invalid stream (php://temp):
96-
- current value :
97-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
98-
bool(false)
99-
- enabling VT100 :
100-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
101-
bool(false)
102-
- current value :
103-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
104-
bool(false)
105-
- disabling VT100:
106-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
80+
- current value : bool(false)
81+
- enabling VT100 :
82+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
10783
bool(false)
108-
- current value :
109-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
84+
- current value : bool(false)
85+
- disabling VT100:
86+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
11087
bool(false)
88+
- current value : bool(false)
11189
Invalid stream (php://input):
112-
- current value :
113-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
114-
bool(false)
115-
- enabling VT100 :
116-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
117-
bool(false)
118-
- current value :
119-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
120-
bool(false)
121-
- disabling VT100:
122-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
90+
- current value : bool(false)
91+
- enabling VT100 :
92+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
12393
bool(false)
124-
- current value :
125-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
94+
- current value :bool(false)
95+
- disabling VT100:
96+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
12697
bool(false)
98+
- current value : bool(false)
12799
Invalid stream (php://memory):
128-
- current value :
129-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
130-
bool(false)
131-
- enabling VT100 :
132-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
133-
bool(false)
134-
- current value :
135-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
136-
bool(false)
137-
- disabling VT100:
138-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
100+
- current value : bool(false)
101+
- enabling VT100 :
102+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
139103
bool(false)
140-
- current value :
141-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
104+
- current value : bool(false)
105+
- disabling VT100:
106+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
142107
bool(false)
108+
- current value : bool(false)
143109
File stream:
144110
- current value : bool(false)
145111
- enabling VT100 : bool(false)

tests/output/sapi_windows_vt100_support_winko_in-err.phpt

+21-55
Original file line numberDiff line numberDiff line change
@@ -76,70 +76,36 @@ STDERR (php://fd/2):
7676
- current value : bool(false)
7777
- disabling VT100: bool(false)
7878
- current value : bool(false)
79-
Not a stream:
80-
- current value :
81-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
82-
bool(false)
83-
- enabling VT100 :
84-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
85-
bool(false)
86-
- current value :
87-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
88-
bool(false)
89-
- disabling VT100:
90-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
91-
bool(false)
92-
- current value :
93-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
94-
bool(false)
9579
Invalid stream (php://temp):
96-
- current value :
97-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
98-
bool(false)
99-
- enabling VT100 :
100-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
101-
bool(false)
102-
- current value :
103-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
104-
bool(false)
105-
- disabling VT100:
106-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
80+
- current value : bool(false)
81+
- enabling VT100 :
82+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
10783
bool(false)
108-
- current value :
109-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
84+
- current value : bool(false)
85+
- disabling VT100:
86+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
11087
bool(false)
88+
- current value : bool(false)
11189
Invalid stream (php://input):
112-
- current value :
113-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
114-
bool(false)
115-
- enabling VT100 :
116-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
117-
bool(false)
118-
- current value :
119-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
120-
bool(false)
121-
- disabling VT100:
122-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
90+
- current value : bool(false)
91+
- enabling VT100 :
92+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
12393
bool(false)
124-
- current value :
125-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
94+
- current value : bool(false)
95+
- disabling VT100:
96+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
12697
bool(false)
98+
- current value : bool(false)
12799
Invalid stream (php://memory):
128-
- current value :
129-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
130-
bool(false)
131-
- enabling VT100 :
132-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
133-
bool(false)
134-
- current value :
135-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
136-
bool(false)
137-
- disabling VT100:
138-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
100+
- current value : bool(false)
101+
- enabling VT100 :
102+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
139103
bool(false)
140-
- current value :
141-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
104+
- current value : bool(false)
105+
- disabling VT100:
106+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
142107
bool(false)
108+
- current value : bool(false)
143109
File stream:
144110
- current value : bool(false)
145111
- enabling VT100 : bool(false)

tests/output/sapi_windows_vt100_support_winko_in-out-err.phpt

+21-55
Original file line numberDiff line numberDiff line change
@@ -76,70 +76,36 @@ STDERR (php://fd/2):
7676
- current value : bool(false)
7777
- disabling VT100: bool(false)
7878
- current value : bool(false)
79-
Not a stream:
80-
- current value :
81-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
82-
bool(false)
83-
- enabling VT100 :
84-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
85-
bool(false)
86-
- current value :
87-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
88-
bool(false)
89-
- disabling VT100:
90-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
91-
bool(false)
92-
- current value :
93-
Warning: sapi_windows_vt100_support(): Argument #1 must be of type resource, string given in %s on line %d
94-
bool(false)
9579
Invalid stream (php://temp):
96-
- current value :
97-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
98-
bool(false)
99-
- enabling VT100 :
100-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
101-
bool(false)
102-
- current value :
103-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
104-
bool(false)
105-
- disabling VT100:
106-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
80+
- current value : bool(false)
81+
- enabling VT100 :
82+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
10783
bool(false)
108-
- current value :
109-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
84+
- current value : bool(false)
85+
- disabling VT100:
86+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
11087
bool(false)
88+
- current value : bool(false)
11189
Invalid stream (php://input):
112-
- current value :
113-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
114-
bool(false)
115-
- enabling VT100 :
116-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
117-
bool(false)
118-
- current value :
119-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
120-
bool(false)
121-
- disabling VT100:
122-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
90+
- current value : bool(false)
91+
- enabling VT100 :
92+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
12393
bool(false)
124-
- current value :
125-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
94+
- current value : bool(false)
95+
- disabling VT100:
96+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
12697
bool(false)
98+
- current value : bool(false)
12799
Invalid stream (php://memory):
128-
- current value :
129-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
130-
bool(false)
131-
- enabling VT100 :
132-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
133-
bool(false)
134-
- current value :
135-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
136-
bool(false)
137-
- disabling VT100:
138-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
100+
- current value : bool(false)
101+
- enabling VT100 :
102+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
139103
bool(false)
140-
- current value :
141-
Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
104+
- current value : bool(false)
105+
- disabling VT100:
106+
Warning: sapi_windows_vt100_support(): not able to analyze the specified stream in %s on line %d
142107
bool(false)
108+
- current value : bool(false)
143109
File stream:
144110
- current value : bool(false)
145111
- enabling VT100 : bool(false)

0 commit comments

Comments
 (0)