Skip to content

Fix integer underflow in Unit.resizeHeader()#25974

Closed
joelreymont wants to merge 1 commit intoziglang:masterfrom
joelreymont:integer-underflow
Closed

Fix integer underflow in Unit.resizeHeader()#25974
joelreymont wants to merge 1 commit intoziglang:masterfrom
joelreymont:integer-underflow

Conversation

@joelreymont
Copy link
Copy Markdown

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.

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

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
```
@alexrp alexrp requested a review from jacobly0 November 19, 2025 19:14
@jacobly0
Copy link
Copy Markdown
Member

How is this change related to an integer underflow?

@s-lambert
Copy link
Copy Markdown

How is this change related to an integer underflow?

It's an AI generated PR but this doesn't show the full reasoning why it's an integer underflow either.

https://x.com/joelreymont/status/1990981118783352952

@jacobly0 jacobly0 closed this Nov 20, 2025
@andrewrk
Copy link
Copy Markdown
Member

Strict No LLM/AI Policy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants