Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions main/streams/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ static int php_stream_memory_seek(php_stream *stream, zend_off_t offset, int whe
php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
assert(ms != NULL);

if (offset == ZEND_LONG_MIN) {
zend_argument_value_error(2, "must be greater than " ZEND_LONG_FMT, ZEND_LONG_MIN);
return FAILURE;
}

switch(whence) {
case SEEK_CUR:
if (offset < 0) {
Expand Down
15 changes: 15 additions & 0 deletions tests/basic/bug20964.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Bug #20964 fseek with PHP_INT_MIN on php://memory
--FILE--
<?php
$stream = fopen('php://memory', 'r+');

$result = fseek($stream, PHP_INT_MIN, SEEK_END);
var_dump($result);
?>
--EXPECTF--
Fatal error: Uncaught ValueError: fseek(): Argument #2 ($offset) must be greater than -%d in %s:%d
Stack trace:
#0 %s(%d): fseek(Resource id #%d, -%d, %d)
#1 {main}
thrown in %s on line %d
Loading