pprof-rs icon indicating copy to clipboard operation
pprof-rs copied to clipboard

fix: use T aligned pointer in TempFdArray

Open Erigara opened this issue 1 year ago • 4 comments

Fix for problem highlighted by #232.

I've observed app crash on my MacOS m1 machine with frame-pointer feature enabled due to unaligned pointer in slice_from_raw_parts.

Direct call to alloc is used to create properly aligned pointer.

ManuallyDrop<T> was used instead of T when creating TempFdArrayIterator to prevent use after drop since try_iter might be called more than once (not sure that strictly required since afaik UnresolvedFrames shouldn't allocate any memory).

Erigara avatar Jan 31 '24 12:01 Erigara

Formatting and clippy should be fine now :)

Erigara avatar Jan 31 '24 13:01 Erigara

@YangKeao hello, do you have any estimates on reviewing this PR?

Erigara avatar Mar 11 '24 09:03 Erigara

We also experience issue #232 on rust nightly-2024-03-05, with pprof as a subdependency of pyroscope_pprofrs. (we get the error in #232 at program startup)

I've tried applying the modifications in this PR, and it appears to fully resolve the startup error in our project. (letting us now use pyroscope_pprofrs)

Is there a blocker on merging of this PR? Or other ways we can help get it validated/merged?

Venryx avatar May 18 '24 17:05 Venryx

hi @Erigara , I am wondering whether there is specific condition that could trigger this panic on unaligned pointer with from_raw_parts.

AFAIK, in any usages of ReportBuilder::build(), self.file_vec.as_ptr() as *const T will make a raw pointer to u8 cast to UnresolvedFrames, which should create an unaligned pointer and trigger panic on any Rust program (preconditon check implemented in Rust core library).

However, not all usage of ReportBuilder::build() will trigger the panic actually (e.g., call_genarate() should trigger panic?)

shinmao avatar Aug 18 '24 22:08 shinmao