diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-07-31 16:21:28 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-07-31 22:10:11 -0700 |
| commit | 2024abda6ae7c02c7fc1667d221e98da23ebcd2a (patch) | |
| tree | a0c03a5630c5145ec4f729d03cd34c7a2b09e811 /lib/std/debug/Dwarf.zig | |
| parent | 95273337c507917e28a6be7dbd89a5c13fea9401 (diff) | |
| download | zig-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/Dwarf.zig')
| -rw-r--r-- | lib/std/debug/Dwarf.zig | 24 |
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(§ion_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(§ion_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, }; |
