Make sure slice::from_raw_parts is not called with null pointer or 0 len in merge_operator
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
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:
Link to the contributing guide provided by the bot is broken. Should be perhaps https://github.com/tikv/tikv/blob/master/CONTRIBUTING.md
PTAL @v01dstar
/approve
/approve
[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
- ~~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
[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.
New changes are detected. LGTM label has been removed.