Skip to content

Commit 8daf792

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Require non-negative length in stream_get_contents()
2 parents 2960301 + 62dce97 commit 8daf792

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

ext/standard/streamsfuncs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ PHP_FUNCTION(stream_get_contents)
429429
Z_PARAM_LONG(desiredpos)
430430
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
431431

432+
if (maxlen < 0 && maxlen != PHP_STREAM_COPY_ALL) {
433+
php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to zero, or -1");
434+
RETURN_FALSE;
435+
}
436+
432437
php_stream_from_zval(stream, zsrc);
433438

434439
if (desiredpos >= 0) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
stream_get_contents() with negative max length
3+
--FILE--
4+
<?php
5+
6+
$tmp = tmpfile();
7+
fwrite($tmp, "abcd");
8+
var_dump(stream_get_contents($tmp, 2, 1));
9+
var_dump(stream_get_contents($tmp, -2));
10+
11+
?>
12+
--EXPECTF--
13+
string(2) "bc"
14+
15+
Warning: stream_get_contents(): Length must be greater than or equal to zero, or -1 in %s on line %d
16+
bool(false)

0 commit comments

Comments
 (0)