cap-primitives 4.0.3 panics with TryFromIntError on a negative macOS st_rdev
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 85/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- rust
調査の方向性
src/rustix/fs/metadata_ext.rs の 171 行目から始め、st_rdev の変換と、そのすぐ上にあるガード付きの st_dev の変換を比較します。cap_std の symlink_metadata パスを追跡して実行時の影響を理解し、その後、macOS の負の st_rdev 値に対してメタデータ処理がパニックしなくなっていること、および関連するプロジェクトのテストが成功することを確認します。
索引モデルが issue の本文から書いたものです。
説明
Summary
ImplMetadataExt::from_rustix panics with TryFromIntError(()) on macOS because it converts st_rdev with u64::try_from(...).unwrap(), while the dev field a few lines above guards the same signedness problem explicitly.
Where
cap-primitives 4.0.3 (newest 4.x on crates.io), rustix backend, src/rustix/fs/metadata_ext.rs:171:
dev: if stat.st_dev < 0 { // ← guarded
i64::try_from(stat.st_dev).unwrap() as u64
} else {
u64::try_from(stat.st_dev).unwrap()
},
ino: stat.st_ino.into(),
...
rdev: u64::try_from(stat.st_rdev).unwrap(), // ← line 171, unguarded
The asymmetry is the whole report. dev handles a negative dev_t and carries a comment acknowledging the platform difference — "platforms where it's unsigned since the first branch here will never be taken" — while rdev, immediately below it, assumes non-negative and unwraps. On macOS dev_t is a signed i32, so st_rdev can be negative and the conversion fails.
Observed
Reached from cap_std's symlink_metadata path, matching the backtrace shape in #328:
called `Result::unwrap()` on an `Err` value: TryFromIntError(())
at cap-primitives-4.0.3/src/rustix/fs/metadata_ext.rs:171
Environment: x86_64-apple-darwin inside a macOS Ventura Recovery guest under QEMU/KVM, stat'ing ordinary files in a temporary directory. The filesystem there reports a negative st_rdev for regular files, which is what triggers it.
I cannot offer a minimal reproduction. I hit this from CI on a Linux host driving a macOS guest, and I have no macOS machine to narrow it to a specific filesystem or file. I am reporting the code asymmetry, which is verifiable by reading the twelve lines above, rather than claiming to have characterised the trigger. If st_rdev is negative only on some filesystems, the guard below is still the right shape.
Relation to #328
Same file, same error type, same class of assumption — an unguarded try_from on a field that is not always non-negative. That one was about negative timestamps; this is a sibling field that the same reasoning applies to. I did not check whether the dev guard was added by that fix, so I am not claiming rdev was missed by it — only that it has the same problem now.
Suggested fix
Guard st_rdev as st_dev is:
rdev: if stat.st_rdev < 0 {
i64::try_from(stat.st_rdev).unwrap() as u64
} else {
u64::try_from(stat.st_rdev).unwrap()
},
or restructure both into a small helper so the next field cannot repeat the mistake. I have not opened a PR because I cannot test the macOS path; the change is yours to make with a reproduction you can actually run.
Impact beyond tests
This is not only a test-fixture problem. It panics inside symlink_metadata, so any cap-std consumer stat'ing a file whose st_rdev is negative fails at runtime on macOS, not merely under a profiler.
- 主要言語
- Rust
- スター
- 821
- フォーク
- 59
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bytecodealliance/cap-std のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
bytecodealliance/cap-std#416 · コメント 2 件 ·
-
Archiving cap-std オープン
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
bytecodealliance/cap-std#426 · コメント 2 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 45/100
bytecodealliance/cap-std#423 · コメント 5 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 42/100
bytecodealliance/cap-std#408 · コメント 4 件 · リアクション 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
bytecodealliance/cap-std#406 · コメント 1 件 · リアクション 2 件 ·
bytecodealliance/cap-std の issue をすべて見る
似ている issue
-
bug github_actions
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
registrystack/registry-stack#1393 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
longbridge/gpui-kit#3223 ·
-
bug engine
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
rocky-data/rocky#2181 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
oasisprotocol/oasis-sdk#2523 ·
-
[indexer] [QA] Add a focused test for the new NonRetryableError / assertSocketAlive() behavior. オープンbot:ai-assisted component:indexer QA-roadmap status:untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
midnightntwrk/midnight-indexer#1557 ·