Skip to content

Commit

Permalink
Merge pull request #36 from mandiant/fix/issue-29
Browse files Browse the repository at this point in the history
Push last fixes
  • Loading branch information
stevemk14ebr committed Aug 15, 2023
2 parents 7e83100 + 45c9fa0 commit 5bd7789
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions debug/gosym/pclntab.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"bytes"
"encoding/binary"
"fmt"
"math"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -352,8 +351,9 @@ func (t *LineTable) go12Funcs() []Func {
}

// avoid OOM error on corrupt binaries
// empirically gathered. Most binaries are <= UINT16_MAX, but some truly huge have >= 100000 functions
ft := t.funcTab()
if ft.Count() >= math.MaxUint16 {
if ft.Count() >= 350000 {
return make([]Func, 1)
}

Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ func main_impl(fileName string, printStdPkgs bool, printFilePaths bool, printTyp
}
}

var knownPclntabVA = uint64(0)
var knownGoTextBase = uint64(0)
restartParseWithRealTextBase:
tabs, err := file.PCLineTable(versionOverride, knownGoTextBase)
tabs, err := file.PCLineTable(versionOverride, knownPclntabVA, knownGoTextBase)
if err != nil {
return ExtractMetadata{}, fmt.Errorf("failed to read pclntab: %w", err)
}
Expand Down Expand Up @@ -223,10 +224,10 @@ restartParseWithRealTextBase:
stomppedMagicMetaConstraintsValid = tab.StompMagicCandidateMeta.SuspectedModuleDataVa == tmpModData.VA
}

if knownGoTextBase == 0 && stomppedMagicMetaConstraintsValid {
if knownGoTextBase == 0 && knownPclntabVA == 0 && stomppedMagicMetaConstraintsValid {
// assign real base and restart pclntab parsing with correct VAs!
// TODO: optimize, we should only restart pclntab parsing of the candidates we know find a moduledata
knownGoTextBase = tmpModData.TextVA
knownPclntabVA = tab.PclntabVA
goto restartParseWithRealTextBase
}

Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestWeirdBins(t *testing.T) {
})

t.Run("fmtisfun_macho", func(t *testing.T) {
testSymbolRecovery(t, "fmtisfun_macho", 0x10be128, 0x1109260, 0x10879b0)
testSymbolRecovery(t, "fmtisfun_macho", 0x10be140, 0x1109260, 0x10879b0)
})

t.Run("fmtisfun_win", func(t *testing.T) {
Expand Down

0 comments on commit 5bd7789

Please sign in to comment.