[go] debug/dwarf: don't crash on negative line file index

7 views
Skip to first unread message

Tobias Klauser (Gerrit)

unread,
Sep 3, 2026, 4:50:35 AMSep 3
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Tobias Klauser has uploaded the change for review

Commit message

debug/dwarf: don't crash on negative line file index

A malformed DWARF line table can cause a DW_LNS_set_file operand to
overflow when converted to int, producing a negative file index
resulting in a panic due to an out-of-bounds slice access in updateFile.

For #47653
Change-Id: Id1ee628add54bb9147700d7000dd5c34474694f4

Change diff

diff --git a/src/debug/dwarf/fuzz_test.go b/src/debug/dwarf/fuzz_test.go
index bc342b0..e653520 100644
--- a/src/debug/dwarf/fuzz_test.go
+++ b/src/debug/dwarf/fuzz_test.go
@@ -14,6 +14,35 @@
f.Skip("Skipping in short mode")
}

+ // A DWARF 4 compile unit with a line program containing a
+ // DW_LNS_set_file instruction with a file index of math.MaxUint64.
+ f.Add(
+ []byte{
+ 1, 0x11, 0,
+ 0x10, 0x17,
+ 0, 0,
+ 0,
+ },
+ []byte{
+ 0x0c, 0, 0, 0,
+ 4, 0,
+ 0, 0, 0, 0,
+ 8,
+ 1,
+ 0, 0, 0, 0,
+ },
+ []byte{
+ 0x25, 0, 0, 0,
+ 4, 0,
+ 0x14, 0, 0, 0,
+ 1, 1, 1, 0, 1, 13,
+ 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1,
+ 0, 0,
+ 4,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 1,
+ },
+ )
+
f.Fuzz(func(t *testing.T, abbrev, info, line []byte) {
d, err := dwarf.New(abbrev, nil, nil, info, line, nil, nil, nil)
if err != nil {
diff --git a/src/debug/dwarf/line.go b/src/debug/dwarf/line.go
index 3811416..f6fe08e 100644
--- a/src/debug/dwarf/line.go
+++ b/src/debug/dwarf/line.go
@@ -465,7 +465,7 @@
// updateFile updates r.state.File after r.fileIndex has
// changed or r.fileEntries has changed.
func (r *LineReader) updateFile() {
- if r.fileIndex < len(r.fileEntries) {
+ if r.fileIndex >= 0 && r.fileIndex < len(r.fileEntries) {
r.state.File = r.fileEntries[r.fileIndex]
} else {
r.state.File = nil

Change information

Files:
  • M src/debug/dwarf/fuzz_test.go
  • M src/debug/dwarf/line.go
Change size: S
Delta: 2 files changed, 30 insertions(+), 1 deletion(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id1ee628add54bb9147700d7000dd5c34474694f4
Gerrit-Change-Number: 827105
Gerrit-PatchSet: 1
Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Ian Lance Taylor (Gerrit)

unread,
Sep 3, 2026, 3:39:27 PMSep 3
to Tobias Klauser, goph...@pubsubhelper.golang.org, Ian Lance Taylor, golang...@luci-project-accounts.iam.gserviceaccount.com, Austin Clements, Than McIntosh, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Austin Clements, Than McIntosh and Tobias Klauser

Ian Lance Taylor voted and added 1 comment

Votes added by Ian Lance Taylor

Code-Review+2

1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Ian Lance Taylor . resolved

Thanks.

Open in Gerrit

Related details

Attention is currently required from:
  • Austin Clements
  • Than McIntosh
  • Tobias Klauser
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id1ee628add54bb9147700d7000dd5c34474694f4
Gerrit-Change-Number: 827105
Gerrit-PatchSet: 1
Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
Gerrit-Reviewer: Austin Clements <aus...@google.com>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Than McIntosh <th...@golang.org>
Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Than McIntosh <th...@golang.org>
Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
Gerrit-Attention: Austin Clements <aus...@google.com>
Gerrit-Comment-Date: Thu, 03 Sep 2026 19:39:22 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Tobias Klauser (Gerrit)

unread,
Sep 3, 2026, 5:00:09 PMSep 3
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Austin Clements, Than McIntosh and Tobias Klauser

Tobias Klauser uploaded new patchset

Tobias Klauser uploaded patch set #2 to this change.
Following approvals got outdated and were removed:
Open in Gerrit

Related details

Attention is currently required from:
  • Austin Clements
  • Than McIntosh
  • Tobias Klauser
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id1ee628add54bb9147700d7000dd5c34474694f4
    Gerrit-Change-Number: 827105
    Gerrit-PatchSet: 2
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Tobias Klauser (Gerrit)

    unread,
    Sep 3, 2026, 5:02:12 PMSep 3
    to goph...@pubsubhelper.golang.org, Ian Lance Taylor, golang...@luci-project-accounts.iam.gserviceaccount.com, Austin Clements, Than McIntosh, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Austin Clements and Than McIntosh

    Tobias Klauser voted Auto-Submit+1

    Auto-Submit+1
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Austin Clements
    • Than McIntosh
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id1ee628add54bb9147700d7000dd5c34474694f4
    Gerrit-Change-Number: 827105
    Gerrit-PatchSet: 2
    Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Reviewer: Austin Clements <aus...@google.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Than McIntosh <th...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Than McIntosh <th...@golang.org>
    Gerrit-Attention: Austin Clements <aus...@google.com>
    Gerrit-Comment-Date: Thu, 03 Sep 2026 21:02:03 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Michael Pratt (Gerrit)

    unread,
    Sep 4, 2026, 6:03:09 PMSep 4
    to Tobias Klauser, goph...@pubsubhelper.golang.org, Michael Pratt, golang...@luci-project-accounts.iam.gserviceaccount.com, Ian Lance Taylor, Austin Clements, Than McIntosh, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Austin Clements, Than McIntosh and Tobias Klauser

    Michael Pratt voted Code-Review+1

    Code-Review+1
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Austin Clements
    • Than McIntosh
    • Tobias Klauser
    Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Id1ee628add54bb9147700d7000dd5c34474694f4
      Gerrit-Change-Number: 827105
      Gerrit-PatchSet: 2
      Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
      Gerrit-Reviewer: Austin Clements <aus...@google.com>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
      Gerrit-Reviewer: Than McIntosh <th...@golang.org>
      Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Attention: Than McIntosh <th...@golang.org>
      Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
      Gerrit-Attention: Austin Clements <aus...@google.com>
      Gerrit-Comment-Date: Fri, 04 Sep 2026 22:03:05 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Tobias Klauser (Gerrit)

      unread,
      Sep 5, 2026, 5:06:55 AMSep 5
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Austin Clements, Than McIntosh and Tobias Klauser

      Tobias Klauser uploaded new patchset

      Tobias Klauser uploaded patch set #3 to this change.
      Following approvals got outdated and were removed:

      Related details

      Attention is currently required from:
      • Austin Clements
      • Than McIntosh
      • Tobias Klauser
      Submit Requirements:
        • requirement satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement is not satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: newpatchset
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Id1ee628add54bb9147700d7000dd5c34474694f4
        Gerrit-Change-Number: 827105
        Gerrit-PatchSet: 3
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Florian Lehner (Gerrit)

        unread,
        Sep 6, 2026, 11:31:00 AMSep 6
        to Tobias Klauser, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Michael Pratt, Ian Lance Taylor, Austin Clements, Than McIntosh, Gopher Robot, golang-co...@googlegroups.com
        Attention needed from Austin Clements, Than McIntosh and Tobias Klauser

        Florian Lehner voted Code-Review+1

        Code-Review+1
        Open in Gerrit

        Related details

        Attention is currently required from:
        • Austin Clements
        • Than McIntosh
        • Tobias Klauser
        Submit Requirements:
          • requirement satisfiedCode-Review
          • requirement satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: Id1ee628add54bb9147700d7000dd5c34474694f4
          Gerrit-Change-Number: 827105
          Gerrit-PatchSet: 3
          Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
          Gerrit-Reviewer: Austin Clements <aus...@google.com>
          Gerrit-Reviewer: Florian Lehner <lhnr...@gmail.com>
          Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
          Gerrit-Reviewer: Than McIntosh <th...@golang.org>
          Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
          Gerrit-CC: Gopher Robot <go...@golang.org>
          Gerrit-Attention: Than McIntosh <th...@golang.org>
          Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
          Gerrit-Attention: Austin Clements <aus...@google.com>
          Gerrit-Comment-Date: Sun, 06 Sep 2026 15:30:52 +0000
          Gerrit-HasComments: No
          Gerrit-Has-Labels: Yes
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Junyang Shao (Gerrit)

          unread,
          Sep 11, 2026, 1:46:35 PMSep 11
          to Tobias Klauser, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Michael Pratt, Ian Lance Taylor, Austin Clements, Than McIntosh, Gopher Robot, golang-co...@googlegroups.com
          Attention needed from Austin Clements, Than McIntosh and Tobias Klauser

          Junyang Shao voted Code-Review+1

          Code-Review+1
          Open in Gerrit

          Related details

          Attention is currently required from:
          • Austin Clements
          • Than McIntosh
          • Tobias Klauser
          Submit Requirements:
            • requirement satisfiedCode-Review
            • requirement satisfiedNo-Unresolved-Comments
            • requirement satisfiedReview-Enforcement
            • requirement satisfiedTryBots-Pass
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: Id1ee628add54bb9147700d7000dd5c34474694f4
            Gerrit-Change-Number: 827105
            Gerrit-PatchSet: 3
            Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
            Gerrit-Reviewer: Austin Clements <aus...@google.com>
            Gerrit-Reviewer: Florian Lehner <lhnr...@gmail.com>
            Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
            Gerrit-Reviewer: Junyang Shao <shaoj...@google.com>
            Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
            Gerrit-Reviewer: Than McIntosh <th...@golang.org>
            Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
            Gerrit-CC: Gopher Robot <go...@golang.org>
            Gerrit-Attention: Than McIntosh <th...@golang.org>
            Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
            Gerrit-Attention: Austin Clements <aus...@google.com>
            Gerrit-Comment-Date: Fri, 11 Sep 2026 17:46:31 +0000
            Gerrit-HasComments: No
            Gerrit-Has-Labels: Yes
            satisfied_requirement
            open
            diffy

            Gopher Robot (Gerrit)

            unread,
            Sep 11, 2026, 1:48:09 PMSep 11
            to Tobias Klauser, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Junyang Shao, golang...@luci-project-accounts.iam.gserviceaccount.com, Michael Pratt, Ian Lance Taylor, Austin Clements, Than McIntosh, golang-co...@googlegroups.com

            Gopher Robot submitted the change with unreviewed changes

            Unreviewed changes

            1 is the latest approved patch-set.
            The change was submitted with unreviewed changes in the following files:

            ```
            The name of the file: src/debug/dwarf/fuzz_test.go
            Insertions: 73, Deletions: 0.

            @@ -6,6 +6,11 @@

            import (
            "debug/dwarf"
            + "debug/elf"
            + "debug/macho"
            + "os"
            + "path/filepath"
            + "strings"
            "testing"
            )

            @@ -14,6 +19,79 @@

            f.Skip("Skipping in short mode")
            }

            +	dwarfSuffix := func(name string) string {
            + switch {
            + // ELF prefixes, see dwarfSuffix in debug/elf.DWARF
            + case strings.HasPrefix(name, ".debug_"):
            + return name[7:]
            + case strings.HasPrefix(name, ".zdebug_"):
            + return name[8:]
            + // machO prefixes, see dwarfSuffix in debug/macho.DWARF
            + case strings.HasPrefix(name, "__debug_"):
            + return name[8:]
            + case strings.HasPrefix(name, "__zdebug_"):
            + return name[9:]
            + default:
            + return ""
            + }
            + }
            +
            + testdata, err := os.ReadDir("testdata")
            + if err != nil {
            + f.Fatalf("failed to read testdata directory: %s", err)
            + }
            + for _, de := range testdata {
            + if de.IsDir() {
            + continue
            + }
            +
            + var abbrev, info, line []byte
            +
            + ext := filepath.Ext(de.Name())
            + name := filepath.Join("testdata", de.Name())
            +
            + switch {
            + case strings.HasPrefix(ext, ".elf"):
            + e, err := elf.Open(name)
            + if err != nil {
            + f.Fatal(err)
            + }
            +
            + for _, s := range e.Sections {
            + switch dwarfSuffix(s.Name) {
            + case "abbrev":
            + abbrev, _ = s.Data()
            + case "info":
            + info, _ = s.Data()
            + case "line":
            + line, _ = s.Data()
            + }
            + }
            + case strings.HasPrefix(ext, ".macho"):
            + m, err := macho.Open(name)
            + if err != nil {
            + f.Fatal(err)
            + }
            +
            + for _, s := range m.Sections {
            + switch dwarfSuffix(s.Name) {
            + case "abbrev":
            + abbrev, _ = s.Data()
            + case "info":
            + info, _ = s.Data()
            + case "line":
            + line, _ = s.Data()
            + }
            + }
            + default:
            + continue
            + }
            +
            + if len(abbrev) > 0 || len(info) > 0 || len(line) > 0 {
            + f.Add(abbrev, info, line)
            + }
            + }

            +
            // A DWARF 4 compile unit with a line program containing a
             	// DW_LNS_set_file instruction with a file index of math.MaxUint64.
             	f.Add(
            ```

            Change information

            Commit message:
            debug/dwarf: don't crash on negative line file index

            A malformed DWARF line table can cause a DW_LNS_set_file operand to
            overflow when converted to int, producing a negative file index
            resulting in a panic due to an out-of-bounds slice access in updateFile.

            For #47653
            Fixes #81184
            Change-Id: Id1ee628add54bb9147700d7000dd5c34474694f4
            Reviewed-by: Michael Pratt <mpr...@google.com>
            Reviewed-by: Junyang Shao <shaoj...@google.com>
            Auto-Submit: Tobias Klauser <tobias....@gmail.com>
            Reviewed-by: Ian Lance Taylor <ia...@golang.org>
            Reviewed-by: Florian Lehner <lhnr...@gmail.com>
            Files:
            • M src/debug/dwarf/fuzz_test.go
            • M src/debug/dwarf/line.go
            Change size: S
            Delta: 2 files changed, 30 insertions(+), 1 deletion(-)
            Branch: refs/heads/master
            Submit Requirements:
            Open in Gerrit
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: merged
            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: Id1ee628add54bb9147700d7000dd5c34474694f4
            Gerrit-Change-Number: 827105
            Gerrit-PatchSet: 4
            Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
            Gerrit-Reviewer: Austin Clements <aus...@google.com>
            Gerrit-Reviewer: Florian Lehner <lhnr...@gmail.com>
            Gerrit-Reviewer: Gopher Robot <go...@golang.org>
            open
            diffy
            satisfied_requirement
            Reply all
            Reply to author
            Forward
            0 new messages