# `Rebase`'s `Iterator` impl yields `RebaseOperation`s that can outlive the `Rebase` (use-after-free in safe code)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 22/100
Hướng nghiên cứu
The bug is in the Iterator impl for Rebase in src/rebase.rs (around lines 220-221), where Item is RebaseOperation<'rebase> and the wrapped pointer belongs to the operations array that git_rebase_free releases on drop. Read RebaseOperation, Rebase::nth and the Drop impl to see how lifetimes are tied, then run the issue's repro under AddressSanitizer. Done means the operation cannot outlive the Rebase in safe code. The issue lists two breaking fixes, so confirm the approach with maintainers before starting.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
impl<'rebase> Iterator for Rebase<'rebase> (src/rebase.rs:220-221) has
type Item = Result<RebaseOperation<'rebase>, Error>, where 'rebase is the lifetime of the
Repository borrow, not a borrow of the Rebase. The wrapped git_rebase_operation * points into
the rebase's operations array, which git_rebase_free frees (rebase.c:1466). Safe code can
therefore keep an operation, drop the Rebase, and read freed memory through kind(), id() or
exec(). Rebase::nth ties its result to &mut self and is not affected. This is the same kind of
problem as #1286 (Remote::get_refspec).
#![forbid(unsafe_code)]
use git2::{Repository, Signature};
fn main() {
let dir = std::env::temp_dir().join(format!("rebase-op-uaf-{}", std::process::id()));
let repo = Repository::init(&dir).unwrap();
let sig = Signature::now("a", "[email protected]").unwrap();
let tree = repo.find_tree(repo.index().unwrap().write_tree().unwrap()).unwrap();
let base = repo.commit(Some("HEAD"), &sig, &sig, "base", &tree, &[]).unwrap();
let base = repo.find_commit(base).unwrap();
let tip = repo.commit(Some("HEAD"), &sig, &sig, "tip", &tree, &[&base]).unwrap();
let branch = repo.find_annotated_commit(tip).unwrap();
let upstream = repo.find_annotated_commit(base.id()).unwrap();
let op = {
let mut rebase = repo.rebase(Some(&branch), Some(&upstream), None, None).unwrap();
let op = rebase.next().unwrap().unwrap();
rebase.abort().unwrap();
op
}; // `rebase` dropped: git_rebase_free
assert_eq!(op.id(), tip); // reads the freed operation
}
With git2-rs at b9d59b6 (main), vendored libgit2 1.9.7, under AddressSanitizer (trimmed):
ERROR: AddressSanitizer: heap-use-after-free on address 0x6d9b53017684
READ of size 20 at 0x6d9b53017684 thread T0
#1 <git2::oid::Oid as git2::util::Binding>::from_raw src/oid.rs:301:20
#2 <git2::rebase::RebaseOperation>::id src/rebase.rs:321:18
freed by thread T0 here:
#3 git_rebase_free libgit2/src/libgit2/rebase.c:1466:2
#4 <git2::rebase::Rebase as core::ops::drop::Drop>::drop src/rebase.rs:252:18
previously allocated by thread T0 here:
#5 rebase_operation_alloc libgit2/src/libgit2/rebase.c:219:19
#7 git_rebase_init libgit2/src/libgit2/rebase.c:736:15
Without a sanitizer the assertion fails: op.id() returns a different id after the drop.
Possible fix
Iterator::Item cannot borrow from the iterator, so a lifetime change alone does not fix it. Either
make RebaseOperation own its data (copy kind, id and exec out of the C struct), or replace
the Iterator impl with a method fn next(&mut self) -> Option<Result<RebaseOperation<'_>, Error>>.
Both are breaking changes.
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.
- Ngôn ngữ chính
- Rust
- Star
- 2.1k
- Fork
- 470
- Merge trung bình
- 2 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 18
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rust-lang/git2-rs
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`stash_foreach` crashes on stash entries with no message or a non-UTF-8 messageCó thể đã có người làm @shivampwm2020 đã nhận 43 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rust-lang/git2-rs
Issue tương tự
-
bug P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Windows microphone listing treats words in a device name as DirectShow labelsCó thể đã có người làm @Sujal-chaudhary đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
clipy-recorder/clipy#447 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
nightly-cleanup
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
max-sixty/worktrunk#4939 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Flaky Test] tests::signer::v0::miner_recovers_when_broadcast_block_delay_across_tenures_occursĐang mởflaky
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
stacks-network/stacks-core#7918 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày