fix: #39 from_bytes_separate 检查 RustCallStatus 返回值

分配失败时将 out 参数置零并 return,避免返回未初始化栈垃圾。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-06-06 12:55:37 +08:00
parent fc9e4eec81
commit fb67b1c13d

View File

@ -157,6 +157,15 @@ pub extern "C" fn ffi_zx_document_ffi_rustbuffer_from_bytes_separate(
&mut call_status,
)
};
// Check if allocation succeeded
if call_status.code != uniffi::RustCallStatusCode::Success {
unsafe {
*out_capacity = 0;
*out_len = 0;
*out_data = std::ptr::null_mut();
}
return;
}
unsafe {
*out_capacity = buf.capacity() as u64;
*out_len = buf.len() as u64;