From: Fabrice Bellard Date: Mon, 26 Oct 2026 10:48:10 +0000 (+0100) Subject: Fix leak in JS_ReadBigInt on truncated input (initial patch by theaddonn) X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=79f58c104c910db5bdf63111f7430a45e65b117a;p=quickjs.git Fix leak in JS_ReadBigInt on truncated input (initial patch by theaddonn) --- diff --git a/quickjs.c b/quickjs.c index 0ef8eba..0be50a9 100644 --- a/quickjs.c +++ b/quickjs.c @@ -39517,14 +39517,13 @@ static int JS_ReadFunctionBytecode(BCReaderState *s, JSFunctionBytecode *b, static JSValue JS_ReadBigInt(BCReaderState *s) { - JSValue obj = JS_UNDEFINED; uint32_t len, i, n; JSBigInt *p; js_limb_t v; uint8_t v8; if (bc_get_leb128(s, &len)) - goto fail; + return JS_EXCEPTION; bc_read_trace(s, "len=%" PRId64 "\n", (int64_t)len); if (len == 0) { /* zero case */ @@ -39533,7 +39532,7 @@ static JSValue JS_ReadBigInt(BCReaderState *s) } p = js_bigint_new(s->ctx, (len - 1) / (JS_LIMB_BITS / 8) + 1); if (!p) - goto fail; + return JS_EXCEPTION; for(i = 0; i < len / (JS_LIMB_BITS / 8); i++) { #if JS_LIMB_BITS == 32 if (bc_get_u32(s, &v)) @@ -39563,7 +39562,7 @@ static JSValue JS_ReadBigInt(BCReaderState *s) bc_read_trace(s, "}\n"); return JS_CompactBigInt(s->ctx, p); fail: - JS_FreeValue(s->ctx, obj); + js_free(s->ctx, p); return JS_EXCEPTION; }