diff --git a/v8js_class.cc b/v8js_class.cc index 17bdeaf..43f8bfe 100644 --- a/v8js_class.cc +++ b/v8js_class.cc @@ -654,7 +654,7 @@ static void v8js_compile_script(zval *this_ptr, const zend_string *str, const ze return; } -static void v8js_execute_script(zval *this_ptr, v8js_script *res, long flags, long time_limit, long memory_limit, zval **return_value) +static void v8js_execute_script(zval *this_ptr, v8js_script *res, long flags, long time_limit, size_t memory_limit, zval **return_value) { v8js_ctx *c = Z_V8JS_CTX_OBJ_P(this_ptr); @@ -702,13 +702,19 @@ static PHP_METHOD(V8Js, executeString) return; } + if (memory_limit < 0) { + zend_throw_exception(php_ce_v8js_exception, + "memory_limit must not be negative", 0); + return; + } + v8js_compile_script(getThis(), str, identifier, &res); if (!res) { RETURN_FALSE; } zend_try { - v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value); + v8js_execute_script(getThis(), res, flags, time_limit, static_cast(memory_limit), &return_value); v8js_script_free(res); } zend_catch { @@ -757,11 +763,17 @@ static PHP_METHOD(V8Js, executeScript) return; } + if (memory_limit < 0) { + zend_throw_exception(php_ce_v8js_exception, + "memory_limit must not be negative", 0); + return; + } + if((res = (v8js_script *)zend_fetch_resource(Z_RES_P(zscript), PHP_V8JS_SCRIPT_RES_NAME, le_v8js_script)) == NULL) { RETURN_FALSE; } - v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value); + v8js_execute_script(getThis(), res, flags, time_limit, static_cast(memory_limit), &return_value); } /* }}} */ @@ -907,14 +919,20 @@ static PHP_METHOD(V8Js, setMemoryLimit) return; } + if (memory_limit < 0) { + zend_throw_exception(php_ce_v8js_exception, + "memory_limit must not be negative", 0); + return; + } + c = Z_V8JS_CTX_OBJ_P(getThis()); - c->memory_limit = memory_limit; + c->memory_limit = static_cast(memory_limit); V8JSG(timer_mutex).lock(); for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin(); it != V8JSG(timer_stack).end(); it ++) { if((*it)->ctx == c && !(*it)->killed) { - (*it)->memory_limit = memory_limit; + (*it)->memory_limit = static_cast(memory_limit); } } V8JSG(timer_mutex).unlock(); diff --git a/v8js_class.h b/v8js_class.h index 40c647c..6fb6f83 100644 --- a/v8js_class.h +++ b/v8js_class.h @@ -44,7 +44,7 @@ struct v8js_ctx { long time_limit; bool time_limit_hit; - long memory_limit; + size_t memory_limit; bool memory_limit_hit; long average_object_size; diff --git a/v8js_timer.cc b/v8js_timer.cc index ba2d8e1..965d865 100644 --- a/v8js_timer.cc +++ b/v8js_timer.cc @@ -124,7 +124,7 @@ void v8js_timer_thread(zend_v8js_globals *globals) /* {{{ */ /* }}} */ -void v8js_timer_push(long time_limit, long memory_limit, v8js_ctx *c) /* {{{ */ +void v8js_timer_push(long time_limit, size_t memory_limit, v8js_ctx *c) /* {{{ */ { V8JSG(timer_mutex).lock(); diff --git a/v8js_timer.h b/v8js_timer.h index 7cf3e6e..97abf09 100644 --- a/v8js_timer.h +++ b/v8js_timer.h @@ -18,14 +18,14 @@ struct v8js_timer_ctx { long time_limit; - long memory_limit; + size_t memory_limit; std::chrono::time_point time_point; v8js_ctx *ctx; bool killed; }; void v8js_timer_thread(zend_v8js_globals *globals); -void v8js_timer_push(long time_limit, long memory_limit, v8js_ctx *c); +void v8js_timer_push(long time_limit, size_t memory_limit, v8js_ctx *c); #endif /* V8JS_TIMER_H */ diff --git a/v8js_v8.cc b/v8js_v8.cc index 9f6293d..2114d38 100644 --- a/v8js_v8.cc +++ b/v8js_v8.cc @@ -95,7 +95,7 @@ void v8js_v8_init() /* {{{ */ * heap allocated memory). */ void v8js_v8_call(v8js_ctx *c, zval **return_value, - long flags, long time_limit, long memory_limit, + long flags, long time_limit, size_t memory_limit, std::function< v8::Local(v8::Isolate *) >& v8_call) /* {{{ */ { char *tz = NULL; diff --git a/v8js_v8.h b/v8js_v8.h index d60b6ad..e2475b0 100644 --- a/v8js_v8.h +++ b/v8js_v8.h @@ -53,7 +53,7 @@ static inline const char * ToCString(const v8::String::Utf8Value &value) /* {{{ void v8js_v8_init(); void v8js_v8_call(v8js_ctx *c, zval **return_value, - long flags, long time_limit, long memory_limit, + long flags, long time_limit, size_t memory_limit, std::function< v8::Local(v8::Isolate *) >& v8_call); void v8js_terminate_execution(v8::Isolate *isolate);