tikv / pprof-rs

A Rust CPU profiler implemented with the help of backtrace-rs
Apache License 2.0
1.29k stars 99 forks source link

validate whether addr is null before constructing slice #194

Open YangKeao opened 1 year ago

YangKeao commented 1 year ago

Signed-off-by: YangKeao yangkeao@chunibyo.icu

Validate whether the address is null before trying to construct the slice. Because in debug build, the from_raw_parts will check whether the addr is null and aligned, if not, it will panic.

The embarrasing part is that this problem cannot be reproduced through test, so the current test cannot cover this situation...

sticnarf commented 1 year ago

The embarrasing part is that this problem cannot be reproduced through test, so the current test cannot cover this situation...

Right... Though there is a assert_unsafe_precondition check in from_raw_parts, we almost always use the prebuilt libstd in release mode which eliminates the checks.

If we enable -Z build-std, we will reproduce the panic.

sticnarf commented 1 year ago

I have no idea about the CI failures due to linking errors...

tiberiusferreira commented 7 months ago

Hey, as a data point, I just hit this and building with release did fix it.

I hit this specifically because I'm a M1 user. So first adding this crate and running it crashed. I read https://github.com/tikv/pprof-rs/issues/187 and enabled the frame pointer feature flag, nightly and added -Z build-std.

Then I hit this.