diff --git a/ext/spl/tests/SplFileObject/bug20921.phpt b/ext/spl/tests/SplFileObject/bug20921.phpt new file mode 100644 index 0000000000000..431abaf222e5d --- /dev/null +++ b/ext/spl/tests/SplFileObject/bug20921.phpt @@ -0,0 +1,10 @@ +--TEST-- +Bug #20921 - Memory stream seek edge case: PHP_INT_MIN with SEEK_END +--FILE-- +fseek(PHP_INT_MIN, SEEK_END)); +--EXPECT-- +int(-1) diff --git a/main/streams/memory.c b/main/streams/memory.c index 2f411ff8e8c9c..37c3dc69e2280 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -128,7 +128,7 @@ static int php_stream_memory_seek(php_stream *stream, zend_off_t offset, int whe switch(whence) { case SEEK_CUR: if (offset < 0) { - if (ms->fpos < (size_t)(-offset)) { + if (ms->fpos < -(size_t)offset) { ms->fpos = 0; *newoffs = -1; return -1; @@ -165,7 +165,7 @@ static int php_stream_memory_seek(php_stream *stream, zend_off_t offset, int whe stream->eof = 0; stream->fatal_error = 0; return 0; - } else if (ZSTR_LEN(ms->data) < (size_t)(-offset)) { + } else if (ZSTR_LEN(ms->data) < -(size_t)offset) { ms->fpos = 0; *newoffs = -1; return -1;