Rust codegen: Map::set mutates a shared ValueMap in place, causing use-after-free on ValueRef::property borrows

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

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

まだ誰も着手していません。

評価

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

調査の方向性

Start with valdi_core/src/valdi_core/rust/collections.rs and trace Map::set, then read the RustValdi.cpp functions valdi_rust_value_ref_get_property and valdi_rust_value_map_set described in the issue. Check how map handles share their ValueMap and how references are kept valid during mutation. Done means Map::set uses copy-on-write so changes do not mutate shared maps or invalidate live ValueRef::property borrows.

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

説明

Found while reviewing https://github.com/Snapchat/Valdi/pull/211 (native Rust code generation). Not blocking that PR.

Map::set mutates a shared ValueMap in place, causing use-after-free on ValueRef::property borrows

File: valdi_core/src/valdi_core/rust/collections.rs

When a ValueRef pointing to a map entry is live (via ValueRef::property) alongside a Map sharing the same underlying ValueMap, calling Map::set can reallocate the map's backing storage and leave that ValueRef dangling (Use-After-Free). The problem starts in Map::set in collections.rs, which mutates the ref-counted ValueMap in place despite Map::clone, Map::to_valdi, and Map::from_valdi all sharing the same Ref<Valdi::ValueMap>.

In RustValdi.cpp, valdi_rust_value_ref_get_property returns &iterator->second — a direct pointer into ValueMap's phmap::flat_hash_map bucket array — as a ValueRef<'a>, while valdi_rust_value_map_set calls map->insert_or_assign(...) directly on the shared map. Inserting enough keys through one Map handle rehashes the FlatMap and frees the old buckets while another Map, Value, or borrowed ValueRef still references them, causing Use-After-Free in safe Rust as well as unexpected mutation across clones.

Make Map::set copy-on-write (clone the ValueMap into a fresh ValdiRustHandle when the handle or underlying ValueMap is shared) so mutating &mut Map never invalidates other handles or borrowed ValueRefs.

主要言語
C++
スター
16.4k
フォーク
539
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

Snapchat/Valdi のほかの issue

Snapchat/Valdi の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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