[BUG] Heap buffer overflow: calling `Repository::find_submodule("/")` → 1-byte read before heap buffer

未关闭
#1,359 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
64/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
git, rust
领域
backend, security

调研方向

The report points to Repository::find_submodule and libgit2’s git_submodule__lookup_with_cache; start by tracing how the / path is handled in that lookup. Reproduce with the provided Rust program and AddressSanitizer command. Done when the call no longer triggers the reported heap-buffer-overflow and the regression is covered by a test.

由索引模型根据 Issue 内容生成。

描述

Can be triggered on the latest commit b9d59b6 (git2, vendored-libgit2 feature), from rust safe code (#![forbid(unsafe_code)]).

Summary

Running the program below prints the following and aborts with a heap-buffer-overflow:

calling find_submodule("/")
==ERROR: AddressSanitizer: heap-buffer-overflow  READ of size 1
  #0 git_submodule__lookup_with_cache
  #1 git_submodule_lookup
  #2 <git2::repo::Repository>::find_submodule
  #3 10r::main

is located 1 bytes before 8-byte region
allocated by thread T0 here:
  #0 realloc
  #6 git_str_puts
  #7 git_submodule__lookup_with_cache
  #8 git_submodule_lookup
  #9 <git2::repo::Repository>::find_submodule

Calling repo.find_submodule("/") on the initialized repository allocates an 8-byte buffer during find_submodule and reads 1 byte before the start of that allocation.

Reproduce

Cargo.toml:

[dependencies]
git2 = { version = "0.21.0", default-features = false, features = ["vendored-libgit2"] }

src/main.rs:

#![forbid(unsafe_code)]
use git2::Repository;
use std::path::Path;

fn main() {
    let dir = Path::new("tmp/git2-10");
    let _ = std::fs::remove_dir_all(dir);
    let repo = Repository::init(dir).expect("Repository::init");
    eprintln!("calling find_submodule(\"/\")");
    let r = repo.find_submodule("/");
    eprintln!("find_submodule -> {:?}", r.err());
    let _ = std::fs::remove_dir_all(dir);
}
CFLAGS="-fsanitize=address" RUSTFLAGS="-Zsanitizer=address" \
  cargo +nightly run -Zbuild-std --target x86_64-unknown-linux-gnu
主要语言
Rust
星标
2.1k
派生
470
平均合并
2 天 17 小时
30 天内合并 PR
18

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rust-lang/git2-rs 的其他 Issue

查看 rust-lang/git2-rs 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。