Skip to content

Commit 43dc65d

Browse files
authored
Fix potential conversion errors (#384)
- fix undefined behavior in double to int conversions - do not pass an `int64_t` to `js_bool()`
1 parent 70a60f0 commit 43dc65d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

quickjs.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10884,6 +10884,8 @@ static __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen,
1088410884
if (JS_TAG_IS_FLOAT64(tag)) {
1088510885
double d;
1088610886
d = JS_VALUE_GET_FLOAT64(val);
10887+
if (!(d >= 0 && d <= UINT32_MAX))
10888+
goto fail;
1088710889
len = (uint32_t)d;
1088810890
if (len != d)
1088910891
goto fail;
@@ -37570,9 +37572,10 @@ static JSValue js_array_includes(JSContext *ctx, JSValue this_val,
3757037572
int argc, JSValue *argv)
3757137573
{
3757237574
JSValue obj, val;
37573-
int64_t len, n, res;
37575+
int64_t len, n;
3757437576
JSValue *arrp;
3757537577
uint32_t count;
37578+
int res;
3757637579

3757737580
obj = JS_ToObject(ctx, this_val);
3757837581
if (js_get_length64(ctx, &len, obj))
@@ -50000,8 +50003,10 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValue this_val,
5000050003
} else
5000150004
if (tag == JS_TAG_FLOAT64) {
5000250005
d = JS_VALUE_GET_FLOAT64(argv[0]);
50003-
v64 = d;
50004-
is_int = (v64 == d);
50006+
if (d >= INT64_MIN && d < 0x1p63) {
50007+
v64 = d;
50008+
is_int = (v64 == d);
50009+
}
5000550010
} else
5000650011
if (tag == JS_TAG_BIG_INT) {
5000750012
JSBigInt *p1 = JS_VALUE_GET_PTR(argv[0]);

0 commit comments

Comments
 (0)