fix(rust): large BigInts bypass Limits::max_heap_bytes

オープン
#113 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@brxs がすでに取り組んでいます。

2026年11月27日 から。

  • #114 @brxs による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
rust

調査の方向性

Start with rust/crates/psychoscript/src/heap.rs and rust/crates/psychoscript/src/builtins/bigint.rs; the issue identifies the zero-size Kind::BigInt accounting and missing Value::Big traversal. Run the provided regression test to reproduce the excessive allocation, then trace heap charging and Walk::value for captured and own-property BigInts. Done means the test returns DiagnosticKind::MemoryLimitExceeded under the 2 MiB limit, with BigNum::Large limb storage and reachable BigInts charged to the heap.

索引モデルが issue の本文から書いたものです。

説明

Summary

In the Rust crate (psychoscript 0.1.3 / dev), Limits::max_heap_bytes does not count heap-allocated BigInts, allowing unbounded RSS growth under a small heap limit.

Cause

heap::object_bytes (rust/crates/psychoscript/src/heap.rs) explicitly returns 0 for Kind::BigInt(_):

Kind::Accessor(_) | Kind::Storage(_) | Kind::BigInt(_) => 0,

Additionally:

  • Walk::value ignores Value::Big, so closure-captured BigInts (Ref::Cell) and own-property BigInts on Error/Closure/Native/Bound objects are never visited during measurement.
  • Vm::heap_big (rust/crates/psychoscript/src/builtins/bigint.rs) does not charge the extra limb byte length of BigNum::Large toward the allocation pacer (charge_heap).
Minimal Reproduction
use psychoscript::{DiagnosticKind, Limits, Runtime};

#[test]
fn large_bigints_bypass_max_heap_bytes() {
    let rt = Runtime::make().limits(Limits {
        max_heap_bytes: Some(2 * 1024 * 1024),
        ..Limits::default()
    });
    let code = "const base = 1n << 1_000_000n; const a = []; for (let i = 0; i < 100; i++) a.push(base + BigInt(i)); return a.length";
    let outcome = rt.execute(code);
    assert_eq!(
        outcome.result.unwrap_err().kind,
        DiagnosticKind::MemoryLimitExceeded
    );
}

Observed: Completes with Ok(100) and grows process RSS by ~115 MiB under a 2 MiB max_heap_bytes limit (similarly when captured by closures a.push(() => x) or stored on function/error properties).
Expected: Stops with DiagnosticKind::MemoryLimitExceeded.

主要言語
Rust
スター
470
フォーク
11
平均マージ
4時間 10分
マージ済み PR(30日)
89

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

anomalyco/psychoscript のほかの issue

anomalyco/psychoscript の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。