[BUG] BigInt memory leak in Atomics.store on detached SharedArrayBuffer

Open Beginner friendly
#537 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
c, javascript
Domain
security

Research direction

Start in quickjs.c at js_atomics_store(), tracing JS_ToBigInt64() through the detached-buffer check in js_atomics_get_ptr(). Reproduce the reported tight loop with a detached BigInt64Array; done when repeated failing Atomics.store calls no longer retain BigInt allocations while still returning the expected error.

Written by the indexing model from the issue text.

Description

Summary

js_atomics_store() in quickjs.c leaks BigInt memory when writing to a BigInt64Array or BigUint64Array backed by a detached SharedArrayBuffer. The function converts the value argument to a BigInt (allocating heap memory) before checking whether the underlying buffer is still valid. When the buffer is detached, the function returns an error but never frees the BigInt.

Root Cause

if (class_id == JS_CLASS_BIG_INT64_ARRAY ||
    class_id == JS_CLASS_BIG_UINT64_ARRAY) {
    int64_t v64;
    if (JS_ToBigInt64(ctx, &v64, val))   // <-- allocates BigInt on heap
        return JS_EXCEPTION;
    // ... later:
    if (js_atomics_get_ptr(...) == NULL)  // <-- detached buffer check
        return JS_EXCEPTION;             // <-- BigInt never freed

The BigInt allocated by JS_ToBigInt64() is not freed on the detached-buffer error path. Each call leaks the BigInt allocation (typically 32+ bytes). In a tight loop, this exhausts available memory.

Impact

Memory leak via crafted JavaScript. An attacker-controlled script can exhaust process memory by repeatedly calling Atomics.store() on a detached BigInt64Array in a loop. This is a denial-of-service condition.

CWE-401, CVSS 5.3

Dominant language
C
Stars
11k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bellard/quickjs

All issues in bellard/quickjs

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.