Skip to content

Commit 8f01581

Browse files
committed
QuickJS Update
* TypedArray.prototype.subarray: fixed the step at which '[[ByteOffset]]' is read bellard/quickjs@c942978 * Fixed buffer overflow in `js_bigint_from_string()` bellard/quickjs@e1c18be * Fixed crash in OP_add_loc if the variable is modified in `JS_ToPrimitiveFree()` bellard/quickjs@1168c21 * Fixed buffer overflow in `js_bigint_to_string1()` bellard/quickjs@9ce5442 * Fixed buffer overflow in `TypedArray.prototype.lastIndexOf()` bellard/quickjs@c927eca * Avoid side effects in `JS_PrintValue()` which may lead to crashes in `print()` and `js_std_promise_rejection_check()` bellard/quickjs@4e0d0b7 * Limit function and regexp bytecode to 1G to avoid buffer overflows (the bytecode generators assume that bytecode offsets can fit a 32 bit signed integer bellard/quickjs@d9ec8f1 * Adjust lastIndex to leading surrogate when inside a surrogate pair in unicode RegExp bellard/quickjs@a4ac84d
1 parent f1cc8de commit 8f01581

File tree

12 files changed

+370
-183
lines changed

12 files changed

+370
-183
lines changed

src/couch_quickjs/patches/01-spidermonkey-185-mode.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
--- quickjs-master/quickjs.c 2025-06-14 05:51:48
2-
+++ quickjs/quickjs.c 2025-06-20 13:56:52
3-
@@ -30599,10 +30599,24 @@
1+
--- quickjs-master/quickjs.c 2025-08-25 12:20:58
2+
+++ quickjs/quickjs.c 2025-08-25 15:10:50
3+
@@ -30776,10 +30776,24 @@
44
if (s->token.val == TOK_FUNCTION ||
55
(token_is_pseudo_keyword(s, JS_ATOM_async) &&
66
peek_token(s, TRUE) == TOK_FUNCTION)) {

src/couch_quickjs/patches/02-test262-makefile.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
--- quickjs-master/Makefile 2025-06-14 05:51:48
2-
+++ quickjs/Makefile 2025-06-20 18:03:41
1+
--- quickjs-master/Makefile 2025-08-25 12:20:58
2+
+++ quickjs/Makefile 2025-08-25 15:27:47
33
@@ -53,6 +53,10 @@
44
#CONFIG_MSAN=y
55
# use UB sanitizer
66
#CONFIG_UBSAN=y
77
+
88
+# TEST262 bootstrap config: commit id and shallow "since" parameter
9-
+TEST262_COMMIT?=3316c0aaf676d657f5a6b33364fa7e579c78ac7f
10-
+TEST262_SINCE?=2025-05-21
9+
+TEST262_COMMIT?=04eaeb99080ceb60d7b86ea0c4bed6355ef4cdcb
10+
+TEST262_SINCE?=2025-08-20
1111

1212
OBJDIR=.obj
1313

src/couch_quickjs/patches/03-test262-yield.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
--- quickjs-master/tests/test262.patch 2025-06-14 05:51:48
2-
+++ quickjs/tests/test262.patch 2025-06-20 18:03:41
1+
--- quickjs-master/tests/test262.patch 2025-08-25 12:20:58
2+
+++ quickjs/tests/test262.patch 2025-08-25 15:10:50
33
@@ -14,9 +14,9 @@
44
+// small: 200,
55
+// long: 1000,

src/couch_quickjs/patches/04-test262-errors.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
--- quickjs-master/test262_errors.txt 2025-06-14 05:51:48
2-
+++ quickjs/test262_errors.txt 2025-06-20 18:03:41
3-
@@ -1,6 +1,8 @@
1+
--- quickjs-master/test262_errors.txt 2025-08-25 12:20:58
2+
+++ quickjs/test262_errors.txt 2025-08-25 15:13:35
3+
@@ -7,6 +7,8 @@
4+
test262/test/annexB/language/expressions/assignmenttargettype/cover-callexpression-and-asyncarrowhead.js:20: SyntaxError: invalid assignment left-hand side
45
test262/test/built-ins/Atomics/notify/retrieve-length-before-index-coercion-non-shared-detached.js:34: TypeError: ArrayBuffer is detached
56
test262/test/built-ins/Atomics/notify/retrieve-length-before-index-coercion-non-shared-detached.js:34: strict mode: TypeError: ArrayBuffer is detached
6-
test262/test/language/module-code/top-level-await/module-graphs-does-not-hang.js:10: TypeError: $DONE() not called
77
+test262/test/language/statements/expression/S12.4_A1.js:15: unexpected error type: Test262: This statement should not be evaluated.
88
+test262/test/language/statements/expression/S12.4_A1.js:15: strict mode: unexpected error type: Test262: This statement should not be evaluated.
99
test262/test/staging/sm/Date/UTC-convert-all-arguments.js:75: Test262Error: index 1: expected 42, got Error: didn't throw Expected SameValue(«Error: didn't throw», «42») to be true

src/couch_quickjs/quickjs/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ PREFIX?=/usr/local
5555
#CONFIG_UBSAN=y
5656

5757
# TEST262 bootstrap config: commit id and shallow "since" parameter
58-
TEST262_COMMIT?=3316c0aaf676d657f5a6b33364fa7e579c78ac7f
59-
TEST262_SINCE?=2025-05-21
58+
TEST262_COMMIT?=04eaeb99080ceb60d7b86ea0c4bed6355ef4cdcb
59+
TEST262_SINCE?=2025-08-20
6060

6161
OBJDIR=.obj
6262

src/couch_quickjs/quickjs/libregexp.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,17 @@ static int compute_stack_size(const uint8_t *bc_buf, int bc_buf_len)
24332433
return stack_size_max;
24342434
}
24352435

2436+
static void *lre_bytecode_realloc(void *opaque, void *ptr, size_t size)
2437+
{
2438+
if (size > (INT32_MAX / 2)) {
2439+
/* the bytecode cannot be larger than 2G. Leave some slack to
2440+
avoid some overflows. */
2441+
return NULL;
2442+
} else {
2443+
return lre_realloc(opaque, ptr, size);
2444+
}
2445+
}
2446+
24362447
/* 'buf' must be a zero terminated UTF-8 string of length buf_len.
24372448
Return NULL if error and allocate an error message in *perror_msg,
24382449
otherwise the compiled bytecode and its length in plen.
@@ -2461,7 +2472,7 @@ uint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size,
24612472
s->total_capture_count = -1;
24622473
s->has_named_captures = -1;
24632474

2464-
dbuf_init2(&s->byte_code, opaque, lre_realloc);
2475+
dbuf_init2(&s->byte_code, opaque, lre_bytecode_realloc);
24652476
dbuf_init2(&s->group_names, opaque, lre_realloc);
24662477

24672478
dbuf_put_u16(&s->byte_code, re_flags); /* first element is the flags */
@@ -3152,6 +3163,7 @@ int lre_exec(uint8_t **capture,
31523163
REExecContext s_s, *s = &s_s;
31533164
int re_flags, i, alloca_size, ret;
31543165
StackInt *stack_buf;
3166+
const uint8_t *cptr;
31553167

31563168
re_flags = lre_get_flags(bc_buf);
31573169
s->is_unicode = (re_flags & (LRE_FLAG_UNICODE | LRE_FLAG_UNICODE_SETS)) != 0;
@@ -3176,8 +3188,17 @@ int lre_exec(uint8_t **capture,
31763188
capture[i] = NULL;
31773189
alloca_size = s->stack_size_max * sizeof(stack_buf[0]);
31783190
stack_buf = alloca(alloca_size);
3191+
3192+
cptr = cbuf + (cindex << cbuf_type);
3193+
if (0 < cindex && cindex < clen && s->cbuf_type == 2) {
3194+
const uint16_t *p = (const uint16_t *)cptr;
3195+
if (is_lo_surrogate(*p) && is_hi_surrogate(p[-1])) {
3196+
cptr = (const uint8_t *)(p - 1);
3197+
}
3198+
}
3199+
31793200
ret = lre_exec_backtrack(s, capture, stack_buf, 0, bc_buf + RE_HEADER_LEN,
3180-
cbuf + (cindex << cbuf_type), FALSE);
3201+
cptr, FALSE);
31813202
lre_realloc(s->opaque, s->state_stack, 0);
31823203
return ret;
31833204
}

src/couch_quickjs/quickjs/quickjs-libc.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4230,17 +4230,15 @@ static void js_std_promise_rejection_check(JSContext *ctx)
42304230
/* main loop which calls the user JS callbacks */
42314231
void js_std_loop(JSContext *ctx)
42324232
{
4233-
JSContext *ctx1;
42344233
int err;
42354234

42364235
for(;;) {
42374236
/* execute the pending jobs */
42384237
for(;;) {
4239-
err = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
4238+
err = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
42404239
if (err <= 0) {
4241-
if (err < 0) {
4242-
js_std_dump_error(ctx1);
4243-
}
4240+
if (err < 0)
4241+
js_std_dump_error(ctx);
42444242
break;
42454243
}
42464244
}
@@ -4271,11 +4269,10 @@ JSValue js_std_await(JSContext *ctx, JSValue obj)
42714269
JS_FreeValue(ctx, obj);
42724270
break;
42734271
} else if (state == JS_PROMISE_PENDING) {
4274-
JSContext *ctx1;
42754272
int err;
4276-
err = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
4273+
err = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
42774274
if (err < 0) {
4278-
js_std_dump_error(ctx1);
4275+
js_std_dump_error(ctx);
42794276
}
42804277
if (err == 0) {
42814278
js_std_promise_rejection_check(ctx);
@@ -4303,6 +4300,7 @@ void js_std_eval_binary(JSContext *ctx, const uint8_t *buf, size_t buf_len,
43034300
if (JS_VALUE_GET_TAG(obj) == JS_TAG_MODULE) {
43044301
js_module_set_import_meta(ctx, obj, FALSE, FALSE);
43054302
}
4303+
JS_FreeValue(ctx, obj);
43064304
} else {
43074305
if (JS_VALUE_GET_TAG(obj) == JS_TAG_MODULE) {
43084306
if (JS_ResolveModule(ctx, obj) < 0) {

0 commit comments

Comments
 (0)