Skip to content

Commit

Permalink
fix(profiling): mismatch in utf8 handling (#2990)
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Engelhardt <[email protected]>
  • Loading branch information
morrisonlevi and realFlowControl authored Dec 12, 2024
1 parent 8273bb7 commit 4bf79f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions profiling/src/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,16 @@ 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_str = unsafe { core::ffi::CStr::from_ptr(file) };
#[cfg(not(zend_error_observer_80))]
let file = unsafe { zend::zai_str_from_zstr(file.as_mut()).into_string() };
let filename_str = unsafe { zai_str_from_zstr(file.as_mut()) };

let filename = filename_str.to_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()
});
}
Expand Down

0 comments on commit 4bf79f2

Please sign in to comment.