authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-31 16:21:28-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-31 22:10:11-07:00
log2024abda6ae7c02c7fc1667d221e98da23ebcd2a
treea0c03a5630c5145ec4f729d03cd34c7a2b09e811
parent95273337c507917e28a6be7dbd89a5c13fea9401

std.debug.Dwarf: work around API deficiency

need to supply a big enough buffer when working with decompression

1 files changed, 17 insertions(+), 7 deletions(-)

lib/std/debug/Dwarf.zig+17-7
......@@ -2019,10 +2019,14 @@ pub fn compactUnwindToDwarfRegNumber(unwind_reg_number: u3) !u8 {
20192019/// This function is to make it handy to comment out the return and make it
20202020/// into a crash when working on this file.
20212021pub fn bad() error{InvalidDebugInfo} {
2022 if (debug_debug_mode) @panic("bad dwarf");
2022 invalidDebugInfoDetected();
20232023 return error.InvalidDebugInfo;
20242024}
20252025
2026fn invalidDebugInfoDetected() void {
2027 if (debug_debug_mode) @panic("bad dwarf");
2028}
2029
20262030fn missing() error{MissingDebugInfo} {
20272031 if (debug_debug_mode) @panic("missing dwarf");
20282032 return error.MissingDebugInfo;
......@@ -2239,13 +2243,19 @@ pub const ElfModule = struct {
22392243 const chdr = section_reader.takeStruct(elf.Chdr, endian) catch continue;
22402244 if (chdr.ch_type != .ZLIB) continue;
22412245
2242 var zlib_stream: std.compress.flate.Decompress = .init(&section_reader, .zlib, &.{});
2243 const decompressed_section = zlib_stream.reader.allocRemaining(gpa, .unlimited) catch continue;
2244 errdefer gpa.free(decompressed_section);
2245 assert(chdr.ch_size == decompressed_section.len);
2246
2246 var decompress: std.compress.flate.Decompress = .init(&section_reader, .zlib, &.{});
2247 var decompressed_section: std.ArrayListUnmanaged(u8) = .empty;
2248 defer decompressed_section.deinit(gpa);
2249 decompress.reader.appendRemainingUnlimited(gpa, null, &decompressed_section, std.compress.flate.history_len) catch {
2250 invalidDebugInfoDetected();
2251 continue;
2252 };
2253 if (chdr.ch_size != decompressed_section.items.len) {
2254 invalidDebugInfoDetected();
2255 continue;
2256 }
22472257 break :blk .{
2248 .data = decompressed_section,
2258 .data = try decompressed_section.toOwnedSlice(gpa),
22492259 .virtual_address = shdr.sh_addr,
22502260 .owned = true,
22512261 };