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 1 commit 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

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign yiwu-arbug for approval. For more information see the Code Review Process.

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

Needs approval from an approver in each of these files:

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

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]>
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

1 participant