fix(rust): duplicate fresh strings bypass Limits::max_heap_bytes
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
Read rust/crates/psychoscript/src/heap.rs, focusing on heap::Walk::string and how Limits::max_heap_bytes is enforced. Run the minimal Rust test or the crate's memory-limit tests, then verify that separately allocated identical strings trigger DiagnosticKind::MemoryLimitExceeded without unbounded RSS growth.
索引モデルが issue の本文から書いたものです。
説明
Summary
In the Rust crate (psychoscript 0.1.3 / dev), Limits::max_heap_bytes can be bypassed with separately allocated identical strings, allowing unbounded RSS growth under a small heap limit.
Cause
heap::Walk::string (rust/crates/psychoscript/src/heap.rs) deduplicates strings by (r.s, r.units) content via texts: FxHashSet<(&str, Option<&[u16]>)>:
let r = self.vm.atoms.sref(s);
if self.texts.insert((r.s, r.units)) {
self.bytes += STRING_BYTES + 2 * r.len16() as u64;
}
However, strings constructed dynamically (e.g. 'x'.repeat(10_000) or string concatenation) each allocate their own buffer and StrId in the string arena (vm.atoms.bufs). Because Walk::string only adds bytes for the first occurrence of a given text, holding 10,000 separately allocated copies of a 10,000-char string measures as ~20 KB instead of ~100+ MB and never trips MemoryLimitExceeded.
Minimal Reproduction
use psychoscript::{DiagnosticKind, Limits, Runtime};
#[test]
fn duplicate_fresh_strings_bypass_max_heap_bytes() {
let rt = Runtime::make().limits(Limits {
max_heap_bytes: Some(2 * 1024 * 1024),
..Limits::default()
});
let code = "const a = []; for (let i = 0; i < 10_000; i++) a.push('x'.repeat(10_000)); return a.length";
let outcome = rt.execute(code);
assert_eq!(
outcome.result.unwrap_err().kind,
DiagnosticKind::MemoryLimitExceeded
);
}
Observed: Completes with Ok(10000) and grows process RSS by ~103 MiB under a 2 MiB max_heap_bytes limit.
Expected: Stops with DiagnosticKind::MemoryLimitExceeded.
(Split out the separate BigInt max_heap_bytes issue into #113.)
- 主要言語
- Rust
- スター
- 470
- フォーク
- 11
- 平均マージ
- 4時間 10分
- マージ済み PR(30日)
- 89
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
anomalyco/psychoscript のほかの issue
-
fix(rust): large BigInts bypass Limits::max_heap_bytes対応中かも @brxs が 2 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
anomalyco/psychoscript#113 ·
メンテナーはふだん 1 日以内に返信
-
fix(rust): Returned::Block deadlocks single-threaded async executors under execute_async対応中かも @brxs が 2 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
anomalyco/psychoscript#110 ·
メンテナーはふだん 1 日以内に返信
-
Importing psychoscript throws RangeError in Safari (WebKit/JavaScriptCore)対応中かも @vibdev が 2 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
anomalyco/psychoscript#100 ·
メンテナーはふだん 1 日以内に返信
-
Runs fail with `setImmediate is not defined` in browsers and Convex's runtime once a program runs longer than ~1 ms対応中かも @fengqiaoqu が 2 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
anomalyco/psychoscript#82 ·
メンテナーはふだん 1 日以内に返信
anomalyco/psychoscript の issue をすべて見る
似ている issue
-
bug good first issue web
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
triage: not actionable
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
oxc-project/oxc#30518 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area: panel
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
frandev94/shattered-islands#98 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信