Skip to content

Commit e083cfa

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Require non-negative length in stream_get_contents()
2 parents a3d0d94 + 8daf792 commit e083cfa

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
@@ -419,6 +419,11 @@ PHP_FUNCTION(stream_get_contents)
419419
Z_PARAM_LONG(desiredpos)
420420
ZEND_PARSE_PARAMETERS_END();
421421

422+
if (maxlen < 0 && maxlen != PHP_STREAM_COPY_ALL) {
423+
php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to zero, or -1");
424+
RETURN_FALSE;
425+
}
426+
422427
php_stream_from_zval(stream, zsrc);
423428

424429
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)