From 497c8f9d47320caaefe60c7a78aa3bb23f6e3714 Mon Sep 17 00:00:00 2001 From: "v.ryabtsev" Date: Tue, 28 Nov 2017 23:25:58 +0700 Subject: [PATCH] Raise error for negative size in array_resize() Instead of trying to allocate invalid size and most probably crashing with out-of-memory --- squirrel/sqbaselib.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/squirrel/sqbaselib.cpp b/squirrel/sqbaselib.cpp index fdca644..5c74693 100644 --- a/squirrel/sqbaselib.cpp +++ b/squirrel/sqbaselib.cpp @@ -542,9 +542,13 @@ static SQInteger array_resize(HSQUIRRELVM v) SQObject &nsize = stack_get(v, 2); SQObjectPtr fill; if(sq_isnumeric(nsize)) { + SQInteger sz = tointeger(nsize); + if (sz<0) + return sq_throwerror(v, _SC("resizing to negative length")); + if(sq_gettop(v) > 2) fill = stack_get(v, 3); - _array(o)->Resize(tointeger(nsize),fill); + _array(o)->Resize(sz,fill); return 0; } return sq_throwerror(v, _SC("size must be a number"));