Fix invalid memory access in BLAKE3

This commit is contained in:
Raúl Marín 2023-12-14 18:47:53 +01:00
parent a0af0392cd
commit 3343d59f80
3 changed files with 9 additions and 4 deletions

View File

@ -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()
}

View File

@ -0,0 +1 @@
95066D9DCEB0F4D60F229EF14F6FD26E692C21E480A582808975E55E39BEE1A6

View File

@ -0,0 +1,3 @@
-- Tags: no-fasttest
-- https://github.com/ClickHouse/ClickHouse/issues/57810
SELECT hex(BLAKE3(BLAKE3('a')));