Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read new Cargo.lock files #530

Open
cod10129 opened this issue Dec 19, 2024 · 6 comments
Open

Cannot read new Cargo.lock files #530

cod10129 opened this issue Dec 19, 2024 · 6 comments

Comments

@cod10129
Copy link

Cargo-geiger cannot read Cargo.lock files created by newer Cargo versions, which makes it unusable unless you use an older version of Cargo to generate a lockfile before running cargo geiger.

Repro

Install a version of Cargo >= 1.83, and cargo-geiger (tested on the latest release, 0.11.7).

cargo new geiger-test
cd geiger-test
cargo generate-lockfile
cargo geiger

Output:

error: Cargo("failed to parse lock file at: ~/geiger-test/Cargo.lock")

Expected output (reproducible if you use Cargo 1.82):

Metric output format: x/y
    x = unsafe code used by the build
    y = total unsafe code found in the crate

Symbols:
    🔒  = No `unsafe` usage found, declares #![forbid(unsafe_code)]
    ❓  = No `unsafe` usage found, missing #![forbid(unsafe_code)]
    ☢️  = `unsafe` usage found

Functions  Expressions  Impls  Traits  Methods  Dependency

0/0        0/0          0/0    0/0     0/0      ❓ geiger-test 0.1.0

0/0        0/0          0/0    0/0     0/0
@shinmao
Copy link

shinmao commented Dec 26, 2024

I also run into this issue with v1.84.0-nightly.

@oherrala
Copy link

oherrala commented Feb 3, 2025

Also can't read Cargo.toml workspace files with resolver = "3". This is also fixed by updating the cargo dependency.

resolver setting 3 is not valid, valid options are "1" or "2"

@meltyness
Copy link

meltyness commented Feb 20, 2025

For future readers, be advised that this sort of thing may have fallen out of vogue or usefulness.

"uses unsafe" is kind of an unreliable or vague heuristic.

You may be better off looking into "Miri" or "CHERI" to understand where your application is inheriting or exhibiting risk.

"Miri" and "CHERI" are referenced in the official docs, at the time of writing, in the context of comprehending consequences with unsafe code: https://doc.rust-lang.org/std/ptr/index.html

@shinmao
Copy link

shinmao commented Feb 20, 2025

@meltyness I am not sure what you mean. I think the users cargo-geiger already realize the risk of unsafe, and that's why this tool can help them find out the inherited unsafe. Do you mean this tool can't be used anymore?

@meltyness
Copy link

meltyness commented Feb 20, 2025

@shinmao
This bash one-liner will naively simulate geiger by looking for .rs files which show signs of unsafe code. It's naive in a way that may produce both false negatives and false positives, but also may serve as a fair heuristic for this.

cargo tree | grep -zP "$(grep -PR "fn unsafe|unsafe \{" ~/.cargo/ 2>/dev/null | cut -d":" -f1 | grep \.rs | cut -d"/" -f8 | perl -p -e 's/[-][0-9]+[.][0-9]+[.][0-9]+[+]?.*$//' | uniq | tr '\n' '|' | perl -p -e 's/\|$//' | perl -p -e 's/[|]/ | /g')"

I'm just saying there's more refined alternatives to this package, which might explain the delay in getting issues with it fixed.

Additionally, a look at other issues suggests that when this worked it ran every build script, which is it's own special kind of thing.

Anyway, I hope this helps!

@meltyness
Copy link

meltyness commented Feb 20, 2025

Here's a specific example about how this is maybe only servicing as a heuristic:

// TODO: Visit macros.

Another solution that could be scripted out pretty easily is to individually cargo check each item in the dependency tree with RUSTFLAGS="-D unsafe_code" left as an exercise.

Obviously the preference towards more analytical solutions like CHERI and Miri mentioned earlier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants