From c45000de73957993a7a29f46d4571c806b07b4ae Mon Sep 17 00:00:00 2001 From: Joel Reymont <18791+joelreymont@users.noreply.github.com> Date: Wed, 19 Nov 2025 05:29:36 +0200 Subject: [PATCH] Fix integer underflow in Unit.resizeHeader() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a DWARF unit has no previous unit (i.e., it's the first unit in a section), the code incorrectly calculated `available_len = 0`, even though there was actually `unit.off` bytes of available space before the unit. ```zig const available_len = if (unit.prev.unwrap()) |prev_unit| prev_excess: { const prev_unit_ptr = sec.getUnit(prev_unit); break :prev_excess unit.off - prev_unit_ptr.off - prev_unit_ptr.len; } else 0; // ← BUG: Should be unit.off, not 0 ``` --- src/link/Dwarf.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index e8fea3c988c7..b4606611f87d 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -635,7 +635,7 @@ const Unit = struct { const available_len = if (unit.prev.unwrap()) |prev_unit| prev_excess: { const prev_unit_ptr = sec.getUnit(prev_unit); break :prev_excess unit.off - prev_unit_ptr.off - prev_unit_ptr.len; - } else 0; + } else unit.off; if (available_len + unit.header_len < len) try unit.resize(sec, dwarf, len - unit.header_len, unit.len - unit.header_len + len); if (unit.header_len > len) {