diff --git a/main/streams/memory.c b/main/streams/memory.c index 2f411ff8e8c9c..e6969e2038e3e 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -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) { diff --git a/tests/basic/bug20964.phpt b/tests/basic/bug20964.phpt new file mode 100644 index 0000000000000..9aae8946818ec --- /dev/null +++ b/tests/basic/bug20964.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #20964 fseek with PHP_INT_MIN on php://memory +--FILE-- + +--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 \ No newline at end of file