Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Unsoundness: `JSValue` (and others) can outlive the `Context`

Open
#38 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, rust
Domain
tooling

Research direction

Start with the Rust reproduction in the issue and trace the definitions of JSContext, JSValue, JSObject, and evaluate_script. Confirm the use-after-free after the Context scope ends, then determine and document a lifetime-safe ownership approach. Done means the reproduction cannot access values after their Context is dropped and the relevant safety behavior is covered by a test.

Written by the indexing model from the issue text.

Description

Hi,

JSValue, JSObject and others are not restricted in the lifetime, therefore are able to outlive the Context, in the best case just crashing the program and in the worst case causing a use-after-free.

The following script reproduces the problem and leads to a segfault (due to an safety check in jsc itself):

use javascriptcore::*;

fn main() {
    let v;
    {
        let ctx = JSContext::default();
        v = evaluate_script(&ctx, "'Hello' + ' ' + 'World'", None, "test.js", 1)
            .expect("Failed to evaluate script");
        println!("Value: {:?}", v.as_string());
    }
    println!("Value: {:?}", v.as_string());
}

Typically, you would add PhantomData to add a phantom lifetime. However, you already hold a raw pointer to the context in these structs and the context should be a widespread object in many real-world users of your bindings, ref-counting the context in Rust with Arc might be the best option.

Kind Regards
Tim

Dominant language
Rust
Stars
54
Forks
4
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 endoli/javascriptcore.rs

All issues in endoli/javascriptcore.rs

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.