Stream: wasi

Topic: hashing bug


view this post on Zulip Andrew Brown (Nov 18 2020 at 17:33):

@Alex Crichton, @Dan Gohman, I think I found a bug but I don't know exactly where things are going wrong: I hash the contents of a file and emit the result, but the result is different when I run the program as a rustc-compiled binary and as a wasm32-wasi file run in Wasmtime. Any ideas?

view this post on Zulip Andrew Brown (Nov 18 2020 at 17:34):

I created an example here: https://github.com/abrown/hashing-example

view this post on Zulip Alex Crichton (Nov 18 2020 at 17:34):

hm that repo is a 404, but what hash algorithm are you using?

view this post on Zulip Andrew Brown (Nov 18 2020 at 17:35):

sorry, just made it public

view this post on Zulip Alex Crichton (Nov 18 2020 at 17:36):

ah yeah the Hash trait is not architecture-independent

view this post on Zulip Alex Crichton (Nov 18 2020 at 17:36):

it hashes usize differently on 32 and 64-bit platforms

view this post on Zulip Andrew Brown (Nov 18 2020 at 17:36):

ooooh

view this post on Zulip Andrew Brown (Nov 18 2020 at 17:37):

so if I get rid of the trait and do the hashing manually I should get the same result, right?

view this post on Zulip Alex Crichton (Nov 18 2020 at 17:38):

you should yeah

view this post on Zulip Andrew Brown (Nov 18 2020 at 17:39):

hooray! solved.

view this post on Zulip Andrew Brown (Nov 18 2020 at 17:39):

thanks, deleting the repo now :smile:

view this post on Zulip Dan Gohman (Nov 18 2020 at 17:40):

Where does it hash a usize? Does Hash implicitly hash the length of a slice?

view this post on Zulip Dan Gohman (Nov 18 2020 at 17:42):

Aha, perhaps it does: https://doc.rust-lang.org/stable/src/core/hash/mod.rs.html#669

view this post on Zulip Dan Gohman (Nov 18 2020 at 17:43):

Which suggests that a way to avoid that would be to call hash_slice instead.

view this post on Zulip Alex Crichton (Nov 18 2020 at 18:00):

ah yeah it's in hashing slices which hashes the length


Last updated: Nov 22 2024 at 16:03 UTC