rust-rocksdb icon indicating copy to clipboard operation
rust-rocksdb copied to clipboard

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

Open define-null opened this issue 1 year ago • 8 comments

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

define-null avatar Sep 20 '24 09:09 define-null

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. :smiley:

ti-chi-bot[bot] avatar Sep 20 '24 09:09 ti-chi-bot[bot]

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

define-null avatar Sep 20 '24 09:09 define-null

PTAL @v01dstar

Connor1996 avatar Oct 14 '24 06:10 Connor1996

/approve

Connor1996 avatar Oct 15 '24 06:10 Connor1996

/approve

Connor1996 avatar Nov 07 '24 08:11 Connor1996

[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[bot] avatar Nov 07 '24 08:11 ti-chi-bot[bot]

[LGTM Timeline notifier]

Timeline:

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

ti-chi-bot[bot] avatar Nov 07 '24 08:11 ti-chi-bot[bot]

New changes are detected. LGTM label has been removed.

ti-chi-bot[bot] avatar Nov 07 '24 08:11 ti-chi-bot[bot]