mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Merge pull request #57876 from Algunenano/fix_msan_in_blake3
Fix invalid memory access in BLAKE3
This commit is contained in:
commit
cf031a1b8e
@ -1,24 +1,25 @@
|
||||
extern crate blake3;
|
||||
extern crate libc;
|
||||
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::ffi::{CString};
|
||||
use std::slice;
|
||||
use std::os::raw::c_char;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn blake3_apply_shim(
|
||||
begin: *const c_char,
|
||||
_size: u32,
|
||||
size: u32,
|
||||
out_char_data: *mut u8,
|
||||
) -> *mut c_char {
|
||||
if begin.is_null() {
|
||||
let err_str = CString::new("input was a null pointer").unwrap();
|
||||
return err_str.into_raw();
|
||||
}
|
||||
let input_res = slice::from_raw_parts(begin as *const u8, size as usize);
|
||||
let mut hasher = blake3::Hasher::new();
|
||||
let input_bytes = CStr::from_ptr(begin);
|
||||
let input_res = input_bytes.to_bytes();
|
||||
hasher.update(input_res);
|
||||
let mut reader = hasher.finalize_xof();
|
||||
|
||||
reader.fill(std::slice::from_raw_parts_mut(out_char_data, blake3::OUT_LEN));
|
||||
std::ptr::null_mut()
|
||||
}
|
||||
|
1
tests/queries/0_stateless/02945_blake3_msan.reference
Normal file
1
tests/queries/0_stateless/02945_blake3_msan.reference
Normal file
@ -0,0 +1 @@
|
||||
95066D9DCEB0F4D60F229EF14F6FD26E692C21E480A582808975E55E39BEE1A6
|
3
tests/queries/0_stateless/02945_blake3_msan.sql
Normal file
3
tests/queries/0_stateless/02945_blake3_msan.sql
Normal file
@ -0,0 +1,3 @@
|
||||
-- Tags: no-fasttest
|
||||
-- https://github.com/ClickHouse/ClickHouse/issues/57810
|
||||
SELECT hex(BLAKE3(BLAKE3('a')));
|
Loading…
Reference in New Issue
Block a user