Skip to content
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

rebis-dev: Fix UB detected by miri in tests #2729

Merged
merged 2 commits into from
Jan 5, 2025

Conversation

adri326
Copy link
Contributor

@adri326 adri326 commented Dec 29, 2024

This fixes two sources of undefined behavior:

  • Heap::drop() could be called while InnerHeap::ptr is null, but it did not account for it, causing it to attempt to free a null pointer.
  • ReservedHeapSection::push_pstr_segment() and Heap::copy_str_within() were using ptr::align_of to compute the number of bytes needed to pad the string with zeroes, but since the underlying buffer (InnerHeap::ptr) itself isn't aligned to size_of::<HeapCellValue>(), the returned values would vary randomly between 0 and 3, sometimes causing those two functions to not mark the cells as allocated.

That second one took me a few hours to track down, since the tests would randomly work again should the stars (literally) align ^^'

This one was a toughie: it turns out that using `ptr::align_of()`` was
a bad idea, since the buffer in `Heap` itself is not aligned to
`Heap::heap_cell_alignment()`, so `ptr::align_of()` would sometimes
return lower values than expected.

That made for an heisenbug: if the alignment of the heap happened to be 4,
then the bug wouldn't trigger.
@triska
Copy link
Contributor

triska commented Dec 30, 2024

After seeing one incredible contribution after another from people who literally see this project for the first time, I have learned that "took me a few hours to track down" from new contributors usually, and also in this case, translates to: "casually corrects a mistake that has haunted us for months or years".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants