From: Dmitry Stogov Date: Wed, 18 Apr 2007 14:23:35 +0000 (+0000) Subject: Fixed crash on win32 in case of negative size X-Git-Tag: RELEASE_1_2_0~282 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2918cda4942d58cbecc65910ab0f6f5712d72753;p=php Fixed crash on win32 in case of negative size --- 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: