Skip to content

Commit 2024abd

Browse files
committed
std.debug.Dwarf: work around API deficiency
need to supply a big enough buffer when working with decompression
1 parent 9527333 commit 2024abd

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

lib/std/debug/Dwarf.zig

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
20212021
pub fn bad() error{InvalidDebugInfo} {
2022-
if (debug_debug_mode) @panic("bad dwarf");
2022+
invalidDebugInfoDetected();
20232023
return error.InvalidDebugInfo;
20242024
}
20252025

2026+
fn invalidDebugInfoDetected() void {
2027+
if (debug_debug_mode) @panic("bad dwarf");
2028+
}
2029+
20262030
fn 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
};

0 commit comments

Comments
 (0)