Fix a bug involving optional non-dev dependencies#111
Fix a bug involving optional non-dev dependencies#111Shnatsel merged 2 commits intorust-secure-code:masterfrom
Conversation
|
That sounds reasonable, but I'm not thrilled about including over 4,000 lines of test data, since it's going to get really difficult to diagnose the issue if it ever reoccurs. Could you minify it? If the issue is as you describe, then simply depending on any crate with optional dependencies should suffice. |
|
I should have explained how the test works. Let me please do that now. The cd ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/flate2-1.1.5
cargo metadata | jq . | sed "s,$HOME,\$HOME,"However, the optional dependency diffThe other two json files exist because the But to your point:
You would prefer a fixture, e.g., a small package that enables an optional feature on a dependency? |
Yes, either that or cargo-metadata output derived from such a minimal fixture. I've gone the fixture route in https://github.com/rust-secure-code/cargo-auditable/tree/master/cargo-auditable/tests/fixtures but I think committing the JSONs produced by |
ff9aea3 to
316352e
Compare
|
I think this does it. I broke the changes into two commits. The first commit adds a fixture and a test (that fails). The second commit implements the fix. Note that, in the fixture, |
|
Looks good. Thanks! |
This PR fixes a bug concerning optional non-dev dependencies.
The bug:
cargo supply-chain json --no-devsuggested a project of mine was no longer relying onlibz-rs-sys: https://github.com/trailofbits/cargo-unmaintained/actions/runs/21091621244/job/60663642551#step:8:98The reason was a difference in
gix-features0.44.1 and 0.45.2. The former listslibz-rs-sysas an optional dependency; the latter does not listlibz-rs-sysat all.Furthermore, to determine a project's dependencies,
extract_non_dev_dependencieswas considering only the project's declared dependencies. What the project actually used was irrelevant. Thus, merely listinglibz-rs-sysas an optional dependency ofgix-features0.44.1 was enough to include it in my project's supply chain.The fix:
extract_non_dev_dependenciesno longer determines dependencies using a project's declared dependencies. Now,extract_non_dev_dependenciesusesresolve.nodesto determine the dependencies the project actually uses.This approach makes
--no-devslightly slower, but it produces more accurate results.If I run the fixed version on the project where I observed the bug, I no longer see
libz-rs-sys, and several other dependencies are eliminated as well.Full disclosure: I used an LLM (Claude) to diagnose the bug, to write the fix, and to prepare the test.