diff --git a/compiler-rt/lib/gwp_asan/common.cpp b/compiler-rt/lib/gwp_asan/common.cpp --- a/compiler-rt/lib/gwp_asan/common.cpp +++ b/compiler-rt/lib/gwp_asan/common.cpp @@ -59,6 +59,11 @@ uintptr_t UncompressedBuffer[kMaxTraceLengthToCollect]; size_t BacktraceLength = Backtrace(UncompressedBuffer, kMaxTraceLengthToCollect); + // Backtrace() returns the number of available frames, which may be greater + // than the number of frames in the buffer. In this case, we need to only pack + // the number of frames that are in the buffer. + if (BacktraceLength > kMaxTraceLengthToCollect) + BacktraceLength = kMaxTraceLengthToCollect; TraceSize = compression::pack(UncompressedBuffer, BacktraceLength, CompressedTrace, AllocationMetadata::kStackFrameStorageBytes);