-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Expected behavior if a crate version's checksum changes #10071
Comments
Just for the sake of searchability, the error that Cargo produces in these cases is:
|
And the origin of this check (although not the "Cargo does the wrong thing if the lockfile is changed" issue) is cargo/src/cargo/core/resolver/resolve.rs Lines 136 to 147 in 77a0379
|
The I've used the For security and integrity of registries, I think Cargo should always assume that releases (identified by the entire |
Problem
It's not clear if this is a bug, a feature request, a bit of both, or not really either, but I felt like it'd be good to have an issue to discuss this in.
Cargo currently has a built-in assumption that the checksum of a given crate version will never change. This is, on the whole a good and helpful assumption. However, the fact that it is assumed and not checked leads to some peculiar behavior and workarounds if that assumption is ever violated (I'll give some reasons for why that may happen in the "Notes" section). I think it'd be valuable for Cargo to yell and scream if it detects a checksum mismatch, but then if explicitly told to adapt to the changed checksum, for Cargo to "do the right thing". Essentially this would be adding some "robustness in depth". That is not currently the case, as this sequence of operations highlights (I left it as a script so it's easier to replicate):
Proposed Solution
I think the way to solve this is for Cargo to use the checksum along with the version anywhere the version is currently used to uniquely identify a crate version. That is, at least:
.crate
files in$CARGO_HOME/cache/
$CARGO_HOME/src/
There may also be other places where the assumption that version implies checksum that I don't know of and that'll also have to be updated. If it's only the three above, this may be a relatively simple fix (🤞).
With these changes, if the lockfile is fixed, Cargo should correctly re-fetch and re-compile anything that needs to be, and thus produce the expected result without further fiddling.
It may also be helpful to allow
cargo update -p
(maybe only with--precise
?) to fix a checksum mismatch rather than requiring an impacted user to blow away or manually edit theirCargo.lock
.Notes
Okay, so, why would this come up in the first place? Aside from the corrupted lockfile case and situations like #7180 (comment), my use-case for this is a somewhat convoluted build setup in which a larger build system invokes Cargo. This larger build system may re-build a crate without human intervention if, say, a non-Cargo dependency changes, but such a re-build could cause that crate's checksum to change if it, say, runs
bindgen
in a build script based on a C header file vended by those non-Cargo dependencies. The larger build system attempts to auto-generate Cargo versions so that such re-builds end up with separate version numbers to avoid exactly this problem, but it has no reliable and scalable way to ensure that the generated version number is distinct from all other generated version numbers. It could, in theory, pick random version numbers (in the patch position), or extract a u64 from the checksum, but that would lose out on the attractive "higher is newer" property of version numbers, and may lead to picking an older version of a dependency, which is obviously not good.Now, this is not to say that my use-case is common, a supported/correct use of Cargo, or even at all sane, but I do think that it highlights a way in which Cargo can be made more robust to more use-cases than it currently is.
The text was updated successfully, but these errors were encountered: