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

Fix undefined behavior in extents::insert #319

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nmeum
Copy link
Contributor

@nmeum nmeum commented Feb 12, 2025

The extents::insert may dereference the end iterator, which is undefined behavior. This occurs when there is no element that is greater than the specified key. In which case, iter will point to the element before the end pointer. The loop body will then increment the iter (causing it to point to the end pointer) and dereference it, unless there is an overlap.

The "borders" test case from test_extents.cc triggers this behavior and causes test failures on some architectures. You can single-step through it with GDB to confirm this, Specifically, this was encountered on the Alpine Linux Edge armhf/x86 builders.

If I understand the semantics correctly, then if we ran into the end iterator at this point we don't need to update ignore_due_to_total_overlap and can leave it as-is.

The extents::insert may dereference the end iterator, which is undefined
behavior. This occurs when there is no element that is greater than the
specified key. In which case, iter will point to the element before the
end pointer. The loop body will then increment the iter (causing it to
point to the end pointer) and dereference it, unless there is an
overlap.

The "borders" test case from `test_extents.cc` triggers this behavior
and causes test failures on some architectures. You can single-step
through it with GDB to confirm this, Specifically, this was encountered
on the Alpine Linux Edge armhf/x86 builders.

If I am understand the semantics correctly, then if we ran into the end
iterator at this point, there can be no overlap and therefore we must
insert the element.
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.

1 participant