`stash_foreach` crashes on stash entries with no message or a non-UTF-8 message
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
src/stash.rsで、issueがstashメッセージの文字列への変換箇所として示しているstash_cbから始めてください。報告された両方のケースの再現手順を使い、callbackがNULLメッセージと無効なUTF-8をどのように処理するか確認してください。stash_foreachがクラッシュやpanicを起こさずに完了し、メッセージがない場合に空文字列を渡せば完了です。
索引モデルが issue の本文から書いたものです。
説明
Calling Repository::stash_foreach with git2 0.21.0 crashes when a stash reflog entry has no message. A non-UTF-8 reflog message causes a panic instead.
This affects applications that enumerate stashes when opening a repository, such as Gitte.
To reproduce this issue, create a repository with a stash, then remove the message from its reflog entry, eg like this:
mkdir stash-repro
cd stash-repro
git init
git config user.name "Test"
git config user.email "[email protected]"
printf 'base\n' > file.txt
git add file.txt
git commit -m "Initial commit"
printf 'changed\n' > file.txt
git stash push -m "Example stash"
cut -f1 .git/logs/refs/stash > .git/logs/refs/stash.tmp
mv .git/logs/refs/stash.tmp .git/logs/refs/stash
Then run this with git2 0.21.0:
fn main() -> Result<(), git2::Error> {
let mut repo = git2::Repository::open(".")?;
repo.stash_foreach(|index, message, oid| {
println!("{index}: {oid} {message}");
true
})?;
Ok(())
}
The process crashes with a segmentation fault. The enumeration should succeed and pass an empty string for the missing message.
The cause is this: in src/stash.rs, stash_cb converts the message with:
CStr::from_ptr(message).to_str().unwrap()
For a reflog entry without a message message is NULL. Passing it to CStr::from_ptr causes undefined behavior.
The same conversion also panics if a message contains invalid UTF-8. This can be reproduced by replacing the message part of the reflog entry with bytes such as b"caf\xe9".
As a workaround, I now use repo.reflog("refs/stash") directly and use entry.message_bytes() with String::from_utf8_lossy. This works with entries without a message and with entries with an invalid UTF-8 message.
- 主要言語
- Rust
- スター
- 2.1k
- フォーク
- 470
- 平均マージ
- 2日 17時間
- マージ済み PR(30日)
- 18
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-lang/git2-rs のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/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 件 ·
メンテナーはふだん 1 日以内に返信
-
[Flaky Test] tests::signer::v0::miner_recovers_when_broadcast_block_delay_across_tenures_occursオープンflaky
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
stacks-network/stacks-core#7918 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信