-
Notifications
You must be signed in to change notification settings - Fork 59
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
fix: remove the "identity" feature #196
Conversation
There are _always_ safer ways to compute an identity hash, and this feature can cause otherwise "safe" code to crash. With this feature enabled, `Code::try_from(codec)?.digest(input)` would crash if `codec` was 0 and `input` was more than 64 bytes. Unfortunately, this was a cargo "feature" so a single dependency enabling it means it's enabled for all other crates in the build. Users of this code migrate to `Multihash::wrap(0, digest)`, which returns an error if the digest is too large instead of panicing. fixes #194
Here's an example of a hack I've needed to prevent code that should "just work" from potentially crashing. I understand that downstream crates should generally use custom |
@mxinden one of the reasons this feature was originally introduces was rust-libp2p. Could you please check if it would be OK for the project if we would merge this change? I really want to prevent that projects stay on old versions/need to fork. |
Thanks for the ping @vmx! As far as I can tell our only usage of Do I understand correctly that we would either have to define our own |
That's also the only place that I've found.
It's not a magic constant, |
IMO, it's also reasonable to include some form of helper function here: pub const IDENTITY_CODE: u64 = 0x0;
pub fn identity_hash<S>(data: &[0]) -> Multihash<S> {
Multihash::wrap(IDENTITY_CODE, data)
} |
There is #289 now which is up-to-date with latest master. |
This feature got merged with #289, hence closing this one. |
There are always safer ways to compute an identity hash, and this feature can cause otherwise "safe" code to crash. With this feature enabled,
Code::try_from(codec)?.digest(input)
would crash ifcodec
was 0 andinput
was more than 64 bytes.Unfortunately, this was a cargo "feature" so a single dependency enabling it means it's enabled for all other crates in the build.
Users of this code migrate to
Multihash::wrap(0, digest)
, which returns an error if the digest is too large instead of panicing.fixes #194