From 4adb7eca6ab2148026a9d2e00379cedfc2038a0d Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Mon, 12 May 2025 19:03:04 -0400 Subject: [PATCH] debug: correctly detect missing entries in `.eh_frame_hdr` --- lib/std/debug/Dwarf.zig | 4 +++- lib/std/debug/SelfInfo.zig | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/std/debug/Dwarf.zig b/lib/std/debug/Dwarf.zig index e5d47ba4911c664671d913e08dab512f02bebea1..06b6c81075e494160f15ddbb6ddf05706b118b70 100644 --- a/lib/std/debug/Dwarf.zig +++ b/lib/std/debug/Dwarf.zig @@ -402,7 +402,7 @@ pub const ExceptionFrameHeader = struct { } } - if (len == 0) return bad(); + if (len == 0) return missing(); fbr.pos = left * entry_size; // Read past the pc_begin field of the entry @@ -460,6 +460,8 @@ pub const ExceptionFrameHeader = struct { @sizeOf(usize), native_endian, ); + + if (pc < fde.pc_begin or pc >= fde.pc_begin + fde.pc_range) return missing(); } }; diff --git a/lib/std/debug/SelfInfo.zig b/lib/std/debug/SelfInfo.zig index ea7ecac4ed019bc60ecf381c6e72657263dea7c8..70f3075de7aba034a6cab8684f8a6ffdce3af23f 100644 --- a/lib/std/debug/SelfInfo.zig +++ b/lib/std/debug/SelfInfo.zig @@ -1633,7 +1633,7 @@ pub fn unwindFrameDwarf( &cie, &fde, ) catch |err| switch (err) { - error.InvalidDebugInfo => { + error.MissingDebugInfo => { // `.eh_frame_hdr` appears to be incomplete, so go ahead and populate `cie_map` // and `fde_list`, and fall back to the binary search logic below. try di.scanCieFdeInfo(allocator, base_address); -- 2.54.0