Skip to content

Commit 1cd5e67

Browse files
past-dueFabrice Bellard
authored andcommitted
fixed buffer overflow in js_bigint_to_string1()
Cherry-pick of bellard/quickjs@9ce5442 Co-authored-by: Fabrice Bellard <fabrice@bellard.org>
1 parent 2f8616c commit 1cd5e67

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

quickjs.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11940,11 +11940,10 @@ static JSValue js_bigint_to_string1(JSContext *ctx, JSValueConst val, int radix)
1194011940
bit_pos = i * log2_radix;
1194111941
pos = bit_pos / JS_LIMB_BITS;
1194211942
shift = bit_pos % JS_LIMB_BITS;
11943-
if (likely((shift + log2_radix) <= JS_LIMB_BITS)) {
11944-
c = r->tab[pos] >> shift;
11945-
} else {
11946-
c = (r->tab[pos] >> shift) |
11947-
(r->tab[pos + 1] << (JS_LIMB_BITS - shift));
11943+
c = r->tab[pos] >> shift;
11944+
if ((shift + log2_radix) > JS_LIMB_BITS &&
11945+
(pos + 1) < r->len) {
11946+
c |= r->tab[pos + 1] << (JS_LIMB_BITS - shift);
1194811947
}
1194911948
c &= (radix - 1);
1195011949
*--q = digits[c];

0 commit comments

Comments
 (0)