Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Restrict atom count in deserializer to 1 million #605

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -35361,7 +35361,12 @@ static JSValue JS_ReadRegExp(BCReaderState *s)
return JS_EXCEPTION;
}

assert(!bc->is_wide_char);
if (bc->is_wide_char) {
js_free_string(ctx->rt, pattern);
js_free_string(ctx->rt, bc);
return JS_ThrowInternalError(ctx, "bad regexp bytecode");
}

if (is_be())
lre_byte_swap(bc->u.str8, bc->len, /*is_byte_swapped*/TRUE);

Expand Down Expand Up @@ -35571,8 +35576,13 @@ static int JS_ReadObjectAtoms(BCReaderState *s)
}
if (bc_get_leb128(s, &s->idx_to_atom_count))
return -1;
if (s->idx_to_atom_count > 1000*1000) {
JS_ThrowInternalError(s->ctx, "unreasonable atom count: %u",
s->idx_to_atom_count);
return -1;
}

bc_read_trace(s, "%d atom indexes {\n", s->idx_to_atom_count);
bc_read_trace(s, "%u atom indexes {\n", s->idx_to_atom_count);

if (s->idx_to_atom_count != 0) {
s->idx_to_atom = js_mallocz(s->ctx, s->idx_to_atom_count *
Expand Down
2 changes: 2 additions & 0 deletions tests/test_bjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ function bjson_test_fuzz()
{
var corpus = [
"EBAAAAAABGA=",
"EObm5oIt",
"EAARABMGBgYGBgYGBgYGBv////8QABEALxH/vy8R/78=",
];
for (var input of corpus) {
var buf = base64decode(input);
Expand Down
Loading