Skip to content
This repository was archived by the owner on Sep 13, 2023. It is now read-only.

Soundness bug using Cursor::iter_from() #79

Closed
panicfarm opened this issue Mar 15, 2020 · 2 comments
Closed

Soundness bug using Cursor::iter_from() #79

panicfarm opened this issue Mar 15, 2020 · 2 comments
Labels
ARCHIVED CLOSED at time of archiving

Comments

@panicfarm
Copy link

panicfarm commented Mar 15, 2020

I ran into a soundness bug by letting an iterator outlive the underlying cursor. In my safe code, I created an iterator using Cursor::iter_from. When Cursor::iter_from returned, the ffi::MDB_cursor got deallocated (during unsafe RoCursor::drop) but the pointer to it was retained inside the iterator that was returned in Cursor::iter_from while my safe code was iterating. That caused the soundness bug when after several successful iterations an unrelated part of the program wrote at that address.

Links to the code:

fn iter_from<K>(&mut self, key: K) -> Iter<'txn>

fn cursor(&self) -> *mut ffi::MDB_cursor;

unsafe { ffi::mdb_cursor_close(self.cursor) }

I would add unsafe to Cursor::iter_from but I understand that this could cause a lot of changes to the API, so another idea may be better.

@amandasaurus
Copy link

I think I am getting this error too, and that it's related to #25 & #5

@cbeck88
Copy link

cbeck88 commented May 29, 2020

I also encountered this problem I think about a year ago in danburkert/lmdb-rs, when trying to return a rust iterator type wrapping the lmdb one, from a database abstraction layer object. It segfaulted a lot and I was never able to debug it, and eventually gave up and backed out of that idea. Thank you for explaining :)

@cknowles-admin cknowles-admin added the ARCHIVED CLOSED at time of archiving label Sep 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ARCHIVED CLOSED at time of archiving
Projects
None yet
Development

No branches or pull requests

4 participants