Skip to content

Commit fd4fe5d

Browse files
committed
expand on unsoundness in the readme
1 parent 72da0aa commit fd4fe5d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,19 @@ will automatically download it.
8080
This wrapper is not currently thread-safe. Like the hash implementations
8181
in the Python standard library, we release the GIL during `update`, to
8282
avoid blocking the entire process. However, that means that calling the
83-
`update` method from multiple threads at the same time is undefined
84-
behavior. We could solve this by putting a `Mutex` inside the wrapper
85-
type, but I'd like to get some expert advice about the best practice
86-
here first.
83+
`update` method on the same object from multiple threads at the same
84+
time is undefined behavior. We could solve this by putting a `Mutex`
85+
inside the wrapper type, but I'd like to get some expert advice about
86+
the best practice here first.
8787

8888
A deeper problem is that another thread might mutate a `bytearray` while
8989
we're hashing it, and while our Rust code is treating it as a `&[u8]`.
9090
That violates Rust's aliasing guarantees and is also technically
9191
undefined behavior. However, the only possible way to solve this while
9292
still supporting `bytearray` would be to retain the GIL. Again, I'm in
9393
need of expert advice.
94+
95+
These concerns are more theoretical than practical, however. If you're
96+
racing to update a hasher, or racing to hash a buffer while it's being
97+
written to, the result is inherently nondeterministic. That's almost
98+
certainly a bug in your program, whether or not it's technically sound.

0 commit comments

Comments
 (0)