From 77e55c538f5e460157f1438102eb6743c3855540 Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Wed, 11 Dec 2024 09:57:18 -0700 Subject: [PATCH 1/3] fix(profiling): mismatch in utf8 handling Happens in timeline filename for zend_error_observer. --- Cargo.lock | 2 +- profiling/src/timeline.rs | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 14963fd9b4..c79063463e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1316,6 +1316,7 @@ dependencies = [ "rmp-serde", "serde", "serde_json", + "tinybytes", "tokio", "tokio-util", "uuid", @@ -1984,7 +1985,6 @@ dependencies = [ "datadog-trace-protobuf", "ddcommon 0.0.1", "http 0.2.11", - "hyper 0.14.28", "serde", "tracing", ] diff --git a/profiling/src/timeline.rs b/profiling/src/timeline.rs index 970de53551..33210a3418 100644 --- a/profiling/src/timeline.rs +++ b/profiling/src/timeline.rs @@ -204,21 +204,20 @@ unsafe extern "C" fn ddog_php_prof_zend_error_observer( } #[cfg(zend_error_observer_80)] - let file = unsafe { - let mut len = 0; - let file = file as *const u8; - while *file.add(len) != 0 { - len += 1; - } - std::str::from_utf8_unchecked(std::slice::from_raw_parts(file, len)).to_string() + let filename = unsafe { + let cstr = core::ffi::CStr::from_ptr(file); + cstr.to_string_lossy().into_owned() }; #[cfg(not(zend_error_observer_80))] - let file = unsafe { zend::zai_str_from_zstr(file.as_mut()).into_string() }; + let filename = unsafe { + let zstr = zai_str_from_zstr(file.as_mut()); + zstr.into_string_lossy().into_owned() + }; let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); if let Some(profiler) = Profiler::get() { let now = now.as_nanos() as i64; - profiler.collect_fatal(now, file, line, unsafe { + profiler.collect_fatal(now, filename, line, unsafe { zend::zai_str_from_zstr(message.as_mut()).into_string() }); } From 1be91fdb7380f97245dc54b15446adb500ff6275 Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Wed, 11 Dec 2024 15:12:57 -0700 Subject: [PATCH 2/3] style: incorporate code review feedback --- profiling/src/timeline.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/profiling/src/timeline.rs b/profiling/src/timeline.rs index 33210a3418..4a47ae9542 100644 --- a/profiling/src/timeline.rs +++ b/profiling/src/timeline.rs @@ -204,15 +204,11 @@ unsafe extern "C" fn ddog_php_prof_zend_error_observer( } #[cfg(zend_error_observer_80)] - let filename = unsafe { - let cstr = core::ffi::CStr::from_ptr(file); - cstr.to_string_lossy().into_owned() - }; + let filename_str = unsafe { core::ffi::CStr::from_ptr(file) }; #[cfg(not(zend_error_observer_80))] - let filename = unsafe { - let zstr = zai_str_from_zstr(file.as_mut()); - zstr.into_string_lossy().into_owned() - }; + let filename_str = unsafe { zai_str_from_zstr(file.as_mut()) }; + + let filename = filename_str.into_string_lossy().into_owned(); let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); if let Some(profiler) = Profiler::get() { From f013c40b5546b28d2cfab31ae5e40a03fc7fa519 Mon Sep 17 00:00:00 2001 From: Florian Engelhardt Date: Thu, 12 Dec 2024 07:56:13 +0100 Subject: [PATCH 3/3] into -> to --- profiling/src/timeline.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profiling/src/timeline.rs b/profiling/src/timeline.rs index 4a47ae9542..efbbd9a1f4 100644 --- a/profiling/src/timeline.rs +++ b/profiling/src/timeline.rs @@ -208,7 +208,7 @@ unsafe extern "C" fn ddog_php_prof_zend_error_observer( #[cfg(not(zend_error_observer_80))] let filename_str = unsafe { zai_str_from_zstr(file.as_mut()) }; - let filename = filename_str.into_string_lossy().into_owned(); + let filename = filename_str.to_string_lossy().into_owned(); let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); if let Some(profiler) = Profiler::get() {