mirror of
https://github.com/php/php-src.git
synced 2024-09-23 10:57:26 +00:00
62dce97973
If the length is not -1, require it to be non-negative. Using such lengths doesn't make sense (as only -1 is special-case to read in chunks, anything else will end up doing a huge upfront allocation) and can lead to string allocation overflow. A similar check is already in place for file_get_contents(). That one does not allow -1 (and uses null instead), but this function is explicitly specified to accept -1, so stick to that behavior.
17 lines
341 B
PHP
17 lines
341 B
PHP
--TEST--
|
|
stream_get_contents() with negative max length
|
|
--FILE--
|
|
<?php
|
|
|
|
$tmp = tmpfile();
|
|
fwrite($tmp, "abcd");
|
|
var_dump(stream_get_contents($tmp, 2, 1));
|
|
var_dump(stream_get_contents($tmp, -2));
|
|
|
|
?>
|
|
--EXPECTF--
|
|
string(2) "bc"
|
|
|
|
Warning: stream_get_contents(): Length must be greater than or equal to zero, or -1 in %s on line %d
|
|
bool(false)
|