Skip to content

Fix UB/crash in new SeqnoToTimeMapping::CopyFromSeqnoRange - #12293

Closed
pdillinger wants to merge 3 commits into
meta:mainfrom
pdillinger:seqno_time_crash_fix
Closed

pdillinger wants to merge 3 commits into
meta:mainfrom
pdillinger:seqno_time_crash_fix

Conversation

@pdillinger

Copy link
Copy Markdown
Contributor

Summary: After #12253 this function has crashed in the crash test, in its call to std::copy. I haven't reproduced the crash directly, but std::copy probably has undefined behavior if the starting iterator is after the ending iterator, which was possible. I've fixed the logic to deal with that case and to add an assertion to check that precondition of std::copy (which appears can be unchecked by std::copy itself even with UBSAN+ASAN).

Also added some unit tests etc. that were unfinished for #12253, and slightly tweak SeqnoToTimeMapping::EnforceMaxTimeSpan handling of zero time span case.

This is intended for patching 8.11.

Test Plan: tests added. Will trigger ~20 runs of the crash test job that saw the crash.

Summary: After meta#12253 this function has crashed in the crash test, in
its call to `std::copy`. I haven't reproduced the crash directly, but
`std::copy` probably has undefined behavior if the starting iterator is
after the ending iterator, which was possible. I've fixed the logic to
deal with that case and to add an assertion to check that precondition
of `std::copy` (which appears can be unchecked by `std::copy` itself
even with UBSAN+ASAN).

Also added some unit tests etc. that were unfinished for meta#12253, and
slightly tweak SeqnoToTimeMapping::EnforceMaxTimeSpan handling of zero
time span case.

This is intended for patching 8.11.

Test Plan: tests added. Will trigger ~20 runs of the crash test job that
saw the crash.
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@pdillinger has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@pdillinger has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@pdillinger has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@jowlyzhang jowlyzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thank you for the improvement!

Just for my learning, why is it preferable to make 0 timespan also have one entry, instead of keeping it empty. Is it to be more logically consistent with the keeping one entry before cutoff invariant?

Comment thread db/seqno_to_time_mapping.cc Resolved
@pdillinger

Copy link
Copy Markdown
Contributor Author

Just for my learning, why is it preferable to make 0 timespan also have one entry, instead of keeping it empty. Is it to be more logically consistent with the keeping one entry before cutoff invariant?

Yes, consistent with keeping one entry <= the cutoff time :)

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@pdillinger merged this pull request in d895eb0.

pdillinger added a commit that referenced this pull request Jan 25, 2024
Summary:
After #12253 this function has crashed in the crash test, in its call to `std::copy`. I haven't reproduced the crash directly, but `std::copy` probably has undefined behavior if the starting iterator is after the ending iterator, which was possible. I've fixed the logic to deal with that case and to add an assertion to check that precondition of `std::copy` (which appears can be unchecked by `std::copy` itself even with UBSAN+ASAN).

Also added some unit tests etc. that were unfinished for #12253, and slightly tweak SeqnoToTimeMapping::EnforceMaxTimeSpan handling of zero time span case.

This is intended for patching 8.11.

Pull Request resolved: #12293

Test Plan: tests added. Will trigger ~20 runs of the crash test job that saw the crash. https://fburl.com/ci/5iiizvfa

Reviewed By: jowlyzhang

Differential Revision: D53090422

Pulled By: pdillinger

fbshipit-source-id: 69d60b1847d9c7e4ae62b153011c2040405db461
Tim-Reed pushed a commit to Tim-Reed/rocksdb that referenced this pull request Oct 1, 2026
Summary:
After meta#12253 this function has crashed in the crash test, in its call to `std::copy`. I haven't reproduced the crash directly, but `std::copy` probably has undefined behavior if the starting iterator is after the ending iterator, which was possible. I've fixed the logic to deal with that case and to add an assertion to check that precondition of `std::copy` (which appears can be unchecked by `std::copy` itself even with UBSAN+ASAN).

Also added some unit tests etc. that were unfinished for meta#12253, and slightly tweak SeqnoToTimeMapping::EnforceMaxTimeSpan handling of zero time span case.

This is intended for patching 8.11.

Pull Request resolved: meta#12293

Test Plan: tests added. Will trigger ~20 runs of the crash test job that saw the crash. https://fburl.com/ci/5iiizvfa

Reviewed By: jowlyzhang

Differential Revision: D53090422

Pulled By: pdillinger

fbshipit-source-id: 69d60b1847d9c7e4ae62b153011c2040405db461
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants