Skip to content

fix(bytecode): reject high-bit-set atom indices in JS_ReadObjectAtoms#1485

Open
andreasrosdal wants to merge 1 commit into
quickjs-ng:masterfrom
nordstjernen-web:claude/sec-bc-atom-validation
Open

fix(bytecode): reject high-bit-set atom indices in JS_ReadObjectAtoms#1485
andreasrosdal wants to merge 1 commit into
quickjs-ng:masterfrom
nordstjernen-web:claude/sec-bc-atom-validation

Conversation

@andreasrosdal
Copy link
Copy Markdown
Contributor

The constant-atom validation used __JS_AtomIsConst(atom), defined as ((int32_t)atom < JS_ATOM_END). Atom values with the high bit set became negative as int32_t and compared "less than JS_ATOM_END", slipping past the check and ending up in s->idx_to_atom for later use as property keys / lookup tags.

Use an unsigned comparison: 0 (JS_ATOM_NULL) and >= JS_ATOM_END are both rejected.

Test: api-test now hands JS_ReadObject a hand-crafted bytecode blob whose type-0 atom slot holds 0x80000001. Before the fix the reader accepts the blob and returns a non-exception value; after the fix the reader throws "out of range atom".

The constant-atom validation used __JS_AtomIsConst(atom), defined as
((int32_t)atom < JS_ATOM_END). Atom values with the high bit set
became negative as int32_t and compared "less than JS_ATOM_END",
slipping past the check and ending up in s->idx_to_atom for later
use as property keys / lookup tags.

Use an unsigned comparison: 0 (JS_ATOM_NULL) and >= JS_ATOM_END are
both rejected.

Test: api-test now hands JS_ReadObject a hand-crafted bytecode blob
whose type-0 atom slot holds 0x80000001. Before the fix the reader
accepts the blob and returns a non-exception value; after the fix
the reader throws "out of range atom".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants