-
Notifications
You must be signed in to change notification settings - Fork 177
Tree borrows violation occurs when using zlib backend #392
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
Comments
Thanks a lot for investigating this issue and sharing your findings! It seems like it would be impossible to find or see this without tooling, and even with your fantastic explanation I am still having trouble to truly understand what's going on, or how to fix this. However, I hope that doesn't prevent anyone from contributing a fix. I also wonder how feasible it would be to run our own test suite under Miri - maybe it would also find this issue, or find even more? |
I was able to recreate this issue in the test I think the main problem here is that the interior of
One possible solution is to leak the |
That's great to hear! Is this Miri failure be something that could be reproduced on CI as well?
Thanks for investigating a solution! Would this leak have the possibility of being amplified? Even if only 16 bytes are leaked, or less, over time the loss will be considerable and might cause long-running processed to run out of memory. Thus I don't know how feasible such a fix would really be in a crate like this. |
We'd just need to implement
My extension to Miri is pretty unstable and requires a separate toolchain, so I wouldn't recommend running it in CI. I'm running an evaluation on a bunch of Rust crates that use the FFI, and I'll be publishing my results, but I don't anticipate that my extension will turn into something that's production-ready. However, the Krabcake project is building an equivalent tool. Once development on that is further along, then you'll be able to run Valgrind in CI to keep these errors from popping up again. |
Ah, right, I didn't realize it's a custom, bleeding edge extension and agree that CI probably shouldn't rely on it just yet. I also hope that memory profiling tools will become more readily available for everybody to use to make |
I've been experimenting with a version of Miri that can execute foreign functions by interpreting the LLVM bytecode that is produced during a crate's build process.
Miri found an instance of undefined behavior in flate2-rs at version 1.0.28. There seems to be a tree borrows violation in the constructors for
ZlibEncoder
andZlibDecoder
. I encountered this error when running several test cases for another crate, twmap, which depends on flate2. Here’s the full error message that occurs when running the test casecustom_test_teeworlds07
from that crateIt seems like zlib creates a cyclic structure on lines 306-307 in deflate.c within the body of the function
deflateInit2_
.The parameter
strm
is a given as a mutable borrow from Rust, on line 277 of c.rs in flate2If
state
is mutated through aDeflate
orInflate
object before the pointer stored instrm->state
is used, then I think that this pointer would become "Disabled," leading to the invalid read.The text was updated successfully, but these errors were encountered: