Skip to content

Commit 0721419

Browse files
past-dueFabrice Bellard
authored andcommitted
fixed buffer overflow in TypedArray.prototype.lastIndexOf()
Cherry-pick of bellard/quickjs@c927eca Co-authored-by: Fabrice Bellard <fabrice@bellard.org>
1 parent 1cd5e67 commit 0721419

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

quickjs.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54945,22 +54945,12 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValueConst this_val,
5494554945
if (special == special_lastIndexOf) {
5494654946
k = len - 1;
5494754947
if (argc > 1) {
54948-
if (JS_ToFloat64(ctx, &d, argv[1]))
54948+
int64_t k1;
54949+
if (JS_ToInt64Clamp(ctx, &k1, argv[1], -1, len - 1, len))
5494954950
goto exception;
54950-
if (isnan(d)) {
54951-
k = 0;
54952-
} else {
54953-
if (d >= 0) {
54954-
if (d < k) {
54955-
k = d;
54956-
}
54957-
} else {
54958-
d += len;
54959-
if (d < 0)
54960-
goto done;
54961-
k = d;
54962-
}
54963-
}
54951+
k = k1;
54952+
if (k < 0)
54953+
goto done;
5496454954
}
5496554955
stop = -1;
5496654956
inc = -1;

0 commit comments

Comments
 (0)