-
Notifications
You must be signed in to change notification settings - Fork 60
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 custom_key_cmp_wrapper being able to unwind to C code (ub) #275
fix custom_key_cmp_wrapper being able to unwind to C code (ub) #275
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much @antonilol to make the crate much more safe than it is already!
BTW what do you use heed for? 😊
@@ -371,16 +373,15 @@ impl Drop for EnvInner { | |||
|
|||
/// A helper function that transforms the LMDB types into Rust types (`MDB_val` into slices) | |||
/// and vice versa, the Rust types into C types (`Ordering` into an integer). | |||
extern "C" fn custom_key_cmp_wrapper<C: Comparator>( | |||
unsafe extern "C" fn custom_key_cmp_wrapper<C: Comparator>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have you added unsafe to this function? Isn't it safe now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still dereferences raw pointers. Should I add a /// # Safety
doc comment with some explanation? It is a private function though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ho! Yeah! You're right. It's a good idea to add a safety note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the safety note
and removed safety comments on the safe traits Comparator and LexicographicComparator
2559961
to
40e3bf8
Compare
I am currently experimenting with changing the database backend of electrs, it currently uses RocksDB but that takes so long to compile. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for the fixes! Merging 🙏
Nice, @antonilol 👌 So, you switch not for the LMDB performances or functionalities but more to reduce compilation times? |
Mainly compile time, but the memory mapped nature of LMDB should also speed up runtime by a bit. Important functionality is about the same, talking about get, put, delete, and iterators. |
[](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [heed](https://togithub.com/Kerollmops/heed) | workspace.dependencies | patch | `0.20.4` -> `0.20.5` | --- ### Release Notes <details> <summary>Kerollmops/heed (heed)</summary> ### [`v0.20.5`](https://togithub.com/meilisearch/heed/releases/tag/v0.20.5): 🛁 [Compare Source](https://togithub.com/Kerollmops/heed/compare/v0.20.4...v0.20.5) <p align="center"><img width="280px" src="https://raw.githubusercontent.com/meilisearch/heed/main/assets/heed-pigeon-logo.png"></a></p> <h1 align="center" >heed</h1> ##### What's Changed * fix function docs (clippy warnings) by @​antonil[https://github.com/meilisearch/heed/pull/273](https://togithub.com/meilisearch/heed/pull/273)ll/273 * fix custom_key_cmp_wrapper being able to unwind to C code (ub) by @​antonil[https://github.com/meilisearch/heed/pull/275](https://togithub.com/meilisearch/heed/pull/275)ll/275 ##### New Contributors * @​antonilol made their first contributi[https://github.com/meilisearch/heed/pull/273](https://togithub.com/meilisearch/heed/pull/273)ll/273 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 3pm on Wednesday" in timezone America/New_York, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- Release Notes: - N/A <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yNi4xIiwidXBkYXRlZEluVmVyIjoiMzguMjYuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
custom_key_cmp_wrapper
may not panic because it is called from C code that does not understand rust panics. If it does, that is undefined behavior.custom_key_cmp_wrapper
will now abort if the Comparator implementation panics. I also removed the safety comments oncompare
andcompare_elem
(the safety comments on the safe trait is what got me to discover this UB)Review note:
is equivalent to
ord as i32