Safe custom WitMap length can cause generated Rust bindings to write past a heap allocation
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 22/100
調査の方向性
Start with the proof of concept: a custom WitMap whose wit_map_len reports 1 but whose IntoIterator yields two pairs, driven through wit_bindgen::generate! with map_type. Read the generated Rust map-lowering code, where the allocation is sized from wit_map_len and entries are written without a bounds check. Run the PoC under Miri to reproduce the out-of-bounds write. Done means the lowering either checks the yielded count against the reported length or rejects the mismatch safely, with the Miri run clean.
索引モデルが issue の本文から書いたものです。
説明
Hi,
I am the Co-Lead of the Cargo Team and was recently hired by the Rust Foundation to help triage AI discovered bugs. This bug was found with AI, namely scrutineer and Astra. Except where specifically labeled this report was written by me. @alexcrichton asked me to file this one as an issue so that it doesn't get lost.
AI text:
Summary
Out-of-bounds heap write in generated Rust bindings with custom WitMap. The safe WitMap customization API allows a custom implementation to report a length inconsistent with its IntoIterator output, but generated Rust map lowering allocates from that reported length and writes every yielded entry without a bounds check. A map reporting one u32/u32 pair and yielding two causes a four-byte write at offset eight of an eight-byte heap allocation, before any host import is called.
Proof of concept
Prerequisites: the Rust nightly toolchain with Miri installed and initialized; the recorded verification and this rerun use nightly-2026-06-24. Save the following two files together. All consumer Rust code is safe.
main.rs:
#[derive(Clone)]
pub struct BadMap<K,V>(Vec<(K,V)>);
impl<K,V> wit_bindgen::rt::WitMap<K,V> for BadMap<K,V> {
fn wit_map_new(_: usize) -> Self { Self(Vec::new()) }
fn wit_map_push(&mut self,k:K,v:V) { self.0.push((k,v)); }
fn wit_map_len(&self) -> usize { 1 }
}
impl<K,V> IntoIterator for BadMap<K,V> {
type Item=(K,V);
type IntoIter=std::vec::IntoIter<(K,V)>;
fn into_iter(self)->Self::IntoIter { self.0.into_iter() }
}
impl<'a,K:Copy,V:Copy> IntoIterator for &'a BadMap<K,V> {
type Item=(K,V);
type IntoIter=std::vec::IntoIter<(K,V)>;
fn into_iter(self)->Self::IntoIter { self.0.clone().into_iter() }
}
wit_bindgen::generate!({
inline: "package test:probe; world probe { import send: func(values: map<u32,u32>); }",
map_type: "crate::BadMap",
});
fn main() {
send(&BadMap(vec![(1,2),(3,4)]));
}
Verbatim diagnostic and top of the Miri stack (other output omitted):
error: Undefined Behavior: memory access failed: attempting to access 4 bytes, but got alloc337+0x8 which is at or beyond the end of the allocation of size 8 bytes
= note: stack backtrace:
0: send
at src/main.rs:18:1: 21:3
1: main
at src/main.rs:23:5: 23:37
- 主要言語
- Rust
- スター
- 1.5k
- フォーク
- 306
- 平均マージ
- 1日 4時間
- マージ済み PR(30日)
- 21
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bytecodealliance/wit-bindgen のほかの issue
-
gen-rust
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
bytecodealliance/wit-bindgen#1791 ·
メンテナーはふだん 1 日以内に返信
-
gen-rust
難易度 3/5 半日 初心者へのやさしさ 55/100
bytecodealliance/wit-bindgen#1787 ·
メンテナーはふだん 1 日以内に返信
-
gen-c#
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
bytecodealliance/wit-bindgen#1759 ·
メンテナーはふだん 1 日以内に返信
-
Async exports never free the block of indirect parameters対応中かも @Aditya1404Sal が 37 日前に担当しました。 オープンasync
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
bytecodealliance/wit-bindgen#1757 ·
メンテナーはふだん 1 日以内に返信
-
gen-rust
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
bytecodealliance/wit-bindgen#1754 · コメント 7 件 ·
メンテナーはふだん 1 日以内に返信
bytecodealliance/wit-bindgen の issue をすべて見る
似ている issue
-
lane:collections todo:ticket
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 3 日以内に返信
-
bugfix
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
storytold/designcraft#3662 ·
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
good first issue tooling
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Nixitov/Riptide-Native#521 ·
メンテナーはふだん 1 日以内に返信