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

Make sure slice::from_raw_parts is not called with null pointer or 0 len in merge_operator #804

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

define-null
Copy link

@define-null define-null commented Sep 20, 2024

It was found that on version 1.81 the slice::from_raw_parts may be called with null pointer or len equal 0 in merge_operator, causing panic:

panicked at library/core/src/panicking.rs:221:5:
unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
stack backtrace:
   0: rust_begin_unwind
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_nounwind_fmt::runtime
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:112:18
   2: core::panicking::panic_nounwind_fmt
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:122:5
   3: core::panicking::panic_nounwind
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:221:5
   4: core::slice::raw::from_raw_parts::precondition_check
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ub_checks.rs:68:21
   5: core::slice::raw::from_raw_parts
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ub_checks.rs:75:17
   6: rocksdb::merge_operator::full_merge_callback
             at /home/runner/.cargo/git/checkouts/rust-rocksdb-c9431d8656f4ae9b/5d72760/src/merge_operator.rs:55:25
   7: _ZNK24crocksdb_mergeoperator_t11FullMergeV2ERKN7rocksdb13MergeOperator19MergeOperationInputEPNS1_20MergeOperationOutputE
             at /home/runner/.cargo/git/checkouts/rust-rocksdb-c9431d8656f4ae9b/5d72760/librocksdb_sys/crocksdb/c.cc:603:41
   8: _ZN7rocksdb11MergeHelper14TimedFullMergeEPKNS_13MergeOperatorERKNS_5SliceEPS5_RKSt6vectorIS4_SaIS4_EEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPNS_6LoggerEPNS_10StatisticsEPNS_11SystemClockEPS4_b
             at /home/runner/.cargo/git/checkouts/rust-rocksdb-c9431d8656f4ae9b/5d72760/librocksdb_sys/rocksdb/db/merge_helper.cc:88:42

This commit fixes it by wrapping slice::from_raw_parts call

Copy link

ti-chi-bot bot commented Sep 20, 2024

Welcome @define-null!

It looks like this is your first PR to tikv/rust-rocksdb 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to tikv/rust-rocksdb. 😃

@ti-chi-bot ti-chi-bot bot added dco-signoff: no Indicates the PR's author has not signed dco. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 20, 2024
@define-null
Copy link
Author

define-null commented Sep 20, 2024

Link to the contributing guide provided by the bot is broken. Should be perhaps https://github.com/tikv/tikv/blob/master/CONTRIBUTING.md

Signed-off-by: Vasilii Demidenok <[email protected]>
@define-null define-null force-pushed the defnull/tikv-fix-from-raw-parts branch from f40ff8e to 16c6cc3 Compare September 20, 2024 09:37
@ti-chi-bot ti-chi-bot bot added dco-signoff: yes Indicates the PR's author has signed the dco. and removed dco-signoff: no Indicates the PR's author has not signed dco. labels Sep 20, 2024
Copy link
Member

@Connor1996 Connor1996 left a comment

Choose a reason for hiding this comment

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

LGTM

@Connor1996
Copy link
Member

PTAL @v01dstar

Copy link

@v01dstar v01dstar left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot ti-chi-bot bot removed the lgtm label Oct 15, 2024
@Connor1996
Copy link
Member

/approve

@ti-chi-bot ti-chi-bot bot added the lgtm label Nov 7, 2024
@Connor1996
Copy link
Member

/approve

Copy link

ti-chi-bot bot commented Nov 7, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Connor1996, v01dstar

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Connor1996,v01dstar]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot removed the lgtm label Nov 7, 2024
Copy link

ti-chi-bot bot commented Nov 7, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-10-14 06:22:03.394352624 +0000 UTC m=+252120.543262448: ☑️ agreed by Connor1996.
  • 2024-10-15 06:43:20.675664865 +0000 UTC m=+339797.824574696: ✖️🔁 reset by Connor1996.
  • 2024-11-07 08:37:25.823045987 +0000 UTC m=+1116558.662201532: ☑️ agreed by Connor1996.
  • 2024-11-07 08:38:00.97159398 +0000 UTC m=+1116593.810749526: ✖️🔁 reset by Connor1996.

Copy link

ti-chi-bot bot commented Nov 7, 2024

New changes are detected. LGTM label has been removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved dco-signoff: yes Indicates the PR's author has signed the dco. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants