diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 7547cd4057d..29a62fe076c 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -425,8 +425,11 @@ PHP_FUNCTION(stream_get_contents) php_stream_from_zval(stream, &zsrc); - if ((pos > 0 || (pos == 0 && ZEND_NUM_ARGS() > 2)) && php_stream_seek(stream, pos, SEEK_SET) < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to position %ld in the stream", pos); + if ((pos != 0L) && php_stream_seek(stream, pos, SEEK_CUR) < 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek %ld bytes from current position in the stream", pos); + RETURN_FALSE; + } else if (pos < 0L) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of bytes to seek must be non-negative, given %ld", pos); RETURN_FALSE; }