aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-07-31 16:21:28 -0700
committerAndrew Kelley <andrew@ziglang.org>2025-07-31 22:10:11 -0700
commit2024abda6ae7c02c7fc1667d221e98da23ebcd2a (patch)
treea0c03a5630c5145ec4f729d03cd34c7a2b09e811 /lib/std/debug
parent95273337c507917e28a6be7dbd89a5c13fea9401 (diff)
downloadzig-2024abda6ae7c02c7fc1667d221e98da23ebcd2a.tar.gz
zig-2024abda6ae7c02c7fc1667d221e98da23ebcd2a.zip
std.debug.Dwarf: work around API deficiency
need to supply a big enough buffer when working with decompression
Diffstat (limited to 'lib/std/debug')
-rw-r--r--lib/std/debug/Dwarf.zig24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/std/debug/Dwarf.zig b/lib/std/debug/Dwarf.zig
index 5fa5dd002a..6237d06cda 100644
--- a/lib/std/debug/Dwarf.zig
+++ b/lib/std/debug/Dwarf.zig
@@ -2019,10 +2019,14 @@ pub fn compactUnwindToDwarfRegNumber(unwind_reg_number: u3) !u8 {
/// This function is to make it handy to comment out the return and make it
/// into a crash when working on this file.
pub fn bad() error{InvalidDebugInfo} {
- if (debug_debug_mode) @panic("bad dwarf");
+ invalidDebugInfoDetected();
return error.InvalidDebugInfo;
}
+fn invalidDebugInfoDetected() void {
+ if (debug_debug_mode) @panic("bad dwarf");
+}
+
fn missing() error{MissingDebugInfo} {
if (debug_debug_mode) @panic("missing dwarf");
return error.MissingDebugInfo;
@@ -2239,13 +2243,19 @@ pub const ElfModule = struct {
const chdr = section_reader.takeStruct(elf.Chdr, endian) catch continue;
if (chdr.ch_type != .ZLIB) continue;
- var zlib_stream: std.compress.flate.Decompress = .init(&section_reader, .zlib, &.{});
- const decompressed_section = zlib_stream.reader.allocRemaining(gpa, .unlimited) catch continue;
- errdefer gpa.free(decompressed_section);
- assert(chdr.ch_size == decompressed_section.len);
-
+ var decompress: std.compress.flate.Decompress = .init(&section_reader, .zlib, &.{});
+ var decompressed_section: std.ArrayListUnmanaged(u8) = .empty;
+ defer decompressed_section.deinit(gpa);
+ decompress.reader.appendRemainingUnlimited(gpa, null, &decompressed_section, std.compress.flate.history_len) catch {
+ invalidDebugInfoDetected();
+ continue;
+ };
+ if (chdr.ch_size != decompressed_section.items.len) {
+ invalidDebugInfoDetected();
+ continue;
+ }
break :blk .{
- .data = decompressed_section,
+ .data = try decompressed_section.toOwnedSlice(gpa),
.virtual_address = shdr.sh_addr,
.owned = true,
};