Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(profiling): mismatch in utf8 handling #2990

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading