From d67dad2a0b54b6e6ae3f7e198bf1fa0600c3fa48 Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Fri, 17 Nov 2023 13:37:24 +0100 Subject: [PATCH] trace: fix invalid event names --- rust/ares/src/trace.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rust/ares/src/trace.rs b/rust/ares/src/trace.rs index fb4a16f..1be61dd 100644 --- a/rust/ares/src/trace.rs +++ b/rust/ares/src/trace.rs @@ -139,8 +139,15 @@ pub unsafe fn write_nock_trace( } let pc = path_to_cord(stack, (*trace_stack).path); - let pclen = met3_usize(pc); - let pc_str = &pc.as_bytes()[0..pclen]; + let pc_len = met3_usize(pc); + let pc_bytes = &pc.as_bytes()[0..pc_len]; + let pc_str = match std::str::from_utf8(pc_bytes) { + Ok(valid) => valid, + Err(error) => { + let (valid, _) = pc_bytes.split_at(error.valid_up_to()); + unsafe { std::str::from_utf8_unchecked(valid) } + } + }; assert_no_alloc::permit_alloc(|| { let obj = object! {