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 a few UBSan failures hit by tests #6649

Merged
merged 2 commits into from
May 24, 2023
Merged

Fix a few UBSan failures hit by tests #6649

merged 2 commits into from
May 24, 2023

Conversation

tgoyne
Copy link
Member

@tgoyne tgoyne commented May 19, 2023

The sectioned results change is fixing an actual out of bounds read, but it hasn't been released yet so no changelog entry for it.

Sanitizer failures haven't been resulting in the CI job actually failing so they just slip through unnoticed. -fno-sanitize-recover=all makes it so that the process aborts with an error after a sanitizer failure.

@tgoyne tgoyne self-assigned this May 19, 2023
@cla-bot cla-bot bot added the cla: yes label May 19, 2023
@tgoyne tgoyne marked this pull request as ready for review May 20, 2023 00:36
@tgoyne tgoyne requested review from ironage and kiburtse May 20, 2023 00:36
// Now load `ValueBase::chunk_size` rows from from the leaf into m_storage.
if constexpr (std::is_same_v<U, int64_t>) {
// If it's an integer leaf, then it contains the method get_chunk() which copies
// these values in a super fast way (only feasible if more than chunk_size in column)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"only feasible if more than chunk_size in column" was actually just always incorrect and this always could have used get_chunk().

// To make Valgrind happy. Todo, I *think* it should work without, now, but if it reappears, add memset again.
// memset(res, 0, 8*8);

if (REALM_X86_OR_X64_TRUE && (w == 1 || w == 2 || w == 4) && ndx + 32 < m_size) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was limited to x86 because unaligned loads work there, but it's illegal c++ regardless and loading byte per byte gets most of the speed benefit anyway.

@@ -1168,62 +1168,75 @@ void Array::update_width_cache_from_header() noexcept
}

// This method reads 8 concecutive values into res[8], starting from index 'ndx'. It's allowed for the 8 values to
// exceed array length; in this case, remainder of res[8] will be left untouched.
// exceed array length; in this case, remainder of res[8] will be be set to 0.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment's been wrong for a long time.

@tgoyne
Copy link
Member Author

tgoyne commented May 22, 2023

Added a changelog entry for the sectioned results bug fix as v13.12.0 was released with the bug.

@@ -142,7 +142,7 @@ ref_type ArrayBlob::replace(size_t begin, size_t end, const char* data, size_t d
return new_root.blob_replace(begin, end, data, data_size, add_zero_term);
}

if (remove_size == add_size && is_read_only() && memcmp(m_data + begin, data, data_size) == 0)
if (remove_size == add_size && is_read_only() && (data_size == 0 || memcmp(m_data + begin, data, data_size) == 0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was this one about? Does memcmp actually access the memory if the length is 0?
I'm trying to understand if this could be a fix for stack traces like the one reported in #6463

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memcmp is defined as taking non-null parameters and passing null is UB. In practice all implementations are fine with null if the length is zero but UBSan complains anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good to know.

@tgoyne tgoyne merged commit 61da27e into master May 24, 2023
@tgoyne tgoyne deleted the tg/ub branch May 24, 2023 01:16
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants