From 2918cda4942d58cbecc65910ab0f6f5712d72753 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 18 Apr 2007 14:23:35 +0000 Subject: [PATCH] Fixed crash on win32 in case of negative size --- main/streams/plain_wrapper.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 420f8a63c7..11e05a4672 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -777,8 +777,13 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void case PHP_STREAM_TRUNCATE_SUPPORTED: return fd == -1 ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK; - case PHP_STREAM_TRUNCATE_SET_SIZE: - return ftruncate(fd, *(ptrdiff_t*)ptrparam) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; + case PHP_STREAM_TRUNCATE_SET_SIZE: { + ptrdiff_t new_size = *(ptrdiff_t*)ptrparam; + if (new_size < 0) { + return PHP_STREAM_OPTION_RETURN_ERR; + } + return ftruncate(fd, new_size) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; + } } default: -- 2.40.0