# `Odb: Sync` lets `Mempack::reset` race with `Odb` writes on another thread
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
The race sits between Mempack::reset and Mempack::dump in src/mempack.rs (lines 35-48), which call the backend without the odb lock, and the Send + Sync claim on Odb in src/odb.rs (lines 23-25). Read the reproducer in the issue and run it under ThreadSanitizer to confirm the race. Done means choosing and implementing a fix: either make reset and dump unsafe with a documented no-concurrent-use requirement, or add locking to libgit2's odb_mempack.c. That choice needs maintainer input first.
由索引模型根据 Issue 内容生成。
描述
Odb is Send + Sync (src/odb.rs:23-25) because "git_odb uses locking and atomics
internally". That covers the git_odb_* functions, which hold the odb's lock while they call into a
backend. Mempack::reset and Mempack::dump (src/mempack.rs:35-48) call git_mempack_reset /
git_mempack_dump on the backend directly, without that lock, and the mempack backend has no lock
of its own. Mempack is !Send, but it only borrows the Odb, so another thread holding &Odb
can write into the backend while the owning thread resets it:
#![forbid(unsafe_code)]
fn main() {
let odb = git2::Odb::new().unwrap();
let mempack = odb.add_new_mempack_backend(1000).unwrap();
std::thread::scope(|s| {
s.spawn(|| {
for i in 0..2000 {
odb.write(git2::ObjectType::Blob, format!("blob {i}").as_bytes()).unwrap();
}
});
for _ in 0..2000 {
mempack.reset().unwrap();
}
});
}
git2-rs b9d59b6 (0.21.0) with libgit2 1.9.7, under ThreadSanitizer (5 runs of 5):
WARNING: ThreadSanitizer: data race
Write of size 8 by thread T1 (mutexes: write M0):
#0 git_odb_mempack_oidmap__resize libgit2/src/libgit2/odb_mempack.c:31:1
#3 impl__write libgit2/src/libgit2/odb_mempack.c:57:6
#4 git_odb_write libgit2/src/libgit2/odb.c:1645:12
Previous read of size 8 by main thread:
#0 git_odb_mempack_oidmap_clear libgit2/src/libgit2/odb_mempack.c:31:1
#1 git_mempack_reset libgit2/src/libgit2/odb_mempack.c:179:2
#2 <git2::mempack::Mempack>::reset
Under AddressSanitizer the same program failed in 6 runs of 6: four with
attempting double-free, two with leaked objects.
Possible fix
A borrow-based fix in the wrapper is not enough, because Repository::odb() can hand out several
Odb handles to the same git_odb. Options are to make Mempack::reset and Mempack::dump
unsafe with the requirement that the odb is not used concurrently, or to add a lock to
libgit2's mempack backend.
Found by Crustify, an experimental
UB/soundness auditing agent developed at UC Berkeley and running on Claude Opus 5.5, then
manually reviewed and independently reproduced.
- 主要语言
- Rust
- 星标
- 2.1k
- 派生
- 470
- 平均合并
- 2 天 17 小时
- 30 天内合并 PR
- 18
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-lang/git2-rs 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
`stash_foreach` crashes on stash entries with no message or a non-UTF-8 message可能已有人在做 @shivampwm2020 于 43 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 68/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 64/100
维护者通常 1 天内回复
查看 rust-lang/git2-rs 的全部 Issue
相似的 Issue
-
bug P2
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
Windows microphone listing treats words in a device name as DirectShow labels可能已有人在做 @Sujal-chaudhary 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 88/100
clipy-recorder/clipy#447 · 2 条评论 ·
维护者通常 1 天内回复
-
nightly-cleanup
难度 2/5 1-3 小时 新手友好度 78/100
max-sixty/worktrunk#4939 · 1 个 reaction ·
维护者通常 1 天内回复
-
flaky
难度 2/5 1-3 小时 新手友好度 68/100
stacks-network/stacks-core#7918 · 1 条评论 ·
维护者通常 2 天内回复