Skip to content

Fix leak in JS_ReadBigInt on truncated input - #1840

Merged
saghul merged 1 commit into
quickjs-ng:masterfrom
theaddonn:fix-bjson-bigint-leak
Oct 24, 2026
Merged

saghul merged 1 commit into
quickjs-ng:masterfrom
theaddonn:fix-bjson-bigint-leak

Conversation

@theaddonn

Copy link
Copy Markdown
Contributor

Fixes #1836

The fail path freed an unused obj but not the bigint. Free the bigint instead and drop the dead variable. Added a test that reads a truncated bigint at every length; it leaks under ASan without the fix.

JS_ReadBigInt allocates the bigint before reading its limbs. If the
input ended partway through, the fail path freed an unused `obj`
variable but not the bigint.

Free the bigint instead and drop the dead variable.

Fixes: quickjs-ng#1836
@saghul

saghul commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Not sure this falls under the "bytecode is to be trusted" rule, WDYT @bnoordhuis ?

@theaddonn

Copy link
Copy Markdown
Contributor Author

This one doesn't need JS_READ_OBJ_BYTECODE. It's plain data with the default flags, and the checksum can be skipped with 0xFFFFFFFF. Either way it's a small fix, but happy to close it if you'd rather not take it.

@bnoordhuis bnoordhuis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a buglet introduced in ad1d1af when we cherry-picked some changes from bellard/master; obj is never used. LGTM.

@saghul
saghul merged commit 7a23d8e into quickjs-ng:master Oct 24, 2026
128 checks passed
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.

Memory leak in JS_ReadBigInt when a bjson payload is truncated inside a BigInt

3 participants