Skip to content

Commit

Permalink
Merge pull request #57929 from ClickHouse/backport/23.11/57876
Browse files Browse the repository at this point in the history
Backport #57876 to 23.11: Fix invalid memory access in BLAKE3 (Rust)
  • Loading branch information
alexey-milovidov committed Dec 15, 2023
2 parents e9ab6f7 + 0998525 commit 85f0b04
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions rust/BLAKE3/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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()
}
Expand Down
1 change: 1 addition & 0 deletions tests/queries/0_stateless/02945_blake3_msan.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
95066D9DCEB0F4D60F229EF14F6FD26E692C21E480A582808975E55E39BEE1A6
3 changes: 3 additions & 0 deletions tests/queries/0_stateless/02945_blake3_msan.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Tags: no-fasttest
-- https://github.com/ClickHouse/ClickHouse/issues/57810
SELECT hex(BLAKE3(BLAKE3('a')));

0 comments on commit 85f0b04

Please sign in to comment.