Conversation
dev_t is signed on some platforms (macOS: i32), and st_rdev has that type just like st_dev. st_dev already sign-extends a negative value; st_rdev went straight through u64::try_from(..).unwrap(), which panics with TryFromIntError on a negative device number. Apply the same conversion, which also matches std's MetadataExt::st_rdev (`st_rdev as u64`).
This was referenced Sep 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #427.
dev_tis signed on some platforms (on macOS it isi32).from_rustixalready handles that forst_devby sign-extending throughi64, butst_rdevhas the same type and went throughu64::try_from(stat.st_rdev).unwrap(), which panics withTryFromIntError(())when the device number is negative. We hit this on an x86_64 macOS host:symlink_metadatapanics atmetadata_ext.rs:171.This applies the existing
st_devconversion tost_rdevand widens the existing comment to cover both. The function's#[allow(unused_comparisons)]already covers platforms wheredev_tis unsigned. Sign-extending matches std:std::os::darwin::fs::MetadataExt::st_rdevreturnsst_rdev as u64.There's no regression test, because a negative
st_rdevcan't be produced portably. The change mirrors thest_devcode a few lines above.Checked locally with Rust 1.95.0:
cargo fmt --all -- --check,cargo test -p cap-primitives(Linux), andcargo check -p cap-primitivesforx86_64-apple-darwinandaarch64-apple-darwin.If this is acceptable, a 4.0.4 patch release would let downstream users pick it up without a
[patch]. Thanks!