{"record":{"id":"afd3a4b8cf1ae0fa","repo":"golang/go","slug":"invalid-section-number-in-symbol-table","errorCode":null,"errorMessage":"invalid section number in symbol table","messagePattern":"invalid section number in symbol table","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/objfile/pe.go","lineNumber":73,"sourceCode":"\n\tvar syms []Sym\n\tfor _, s := range f.pe.Symbols {\n\t\tconst (\n\t\t\tN_UNDEF = 0  // An undefined (extern) symbol\n\t\t\tN_ABS   = -1 // An absolute symbol (e_value is a constant, not an address)\n\t\t\tN_DEBUG = -2 // A debugging symbol\n\t\t)\n\t\tsym := Sym{Name: s.Name, Addr: uint64(s.Value), Code: '?'}\n\t\tswitch s.SectionNumber {\n\t\tcase N_UNDEF:\n\t\t\tsym.Code = 'U'\n\t\tcase N_ABS:\n\t\t\tsym.Code = 'C'\n\t\tcase N_DEBUG:\n\t\t\tsym.Code = '?'\n\t\tdefault:\n\t\t\tif s.SectionNumber < 0 || len(f.pe.Sections) < int(s.SectionNumber) {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid section number in symbol table\")\n\t\t\t}\n\t\t\tsect := f.pe.Sections[s.SectionNumber-1]\n\t\t\tconst (\n\t\t\t\ttext  = 0x20\n\t\t\t\tdata  = 0x40\n\t\t\t\tbss   = 0x80\n\t\t\t\tpermW = 0x80000000\n\t\t\t)\n\t\t\tch := sect.Characteristics\n\t\t\tswitch {\n\t\t\tcase ch&text != 0:\n\t\t\t\tsym.Code = 'T'\n\t\t\tcase ch&data != 0:\n\t\t\t\tif ch&permW == 0 {\n\t\t\t\t\tsym.Code = 'R'\n\t\t\t\t} else if bssSectionNumber == s.SectionNumber && bssAddr > 0 && s.Value >= bssAddr {\n\t\t\t\t\t// Past runtime.bss is BSS.\n\t\t\t\t\tsym.Code = 'B'","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/objfile/pe.go#L55-L91","documentation":"When parsing PE (Windows) symbol tables, each symbol references a section by its `SectionNumber`. After handling special cases (N_UNDEF, N_ABS, N_DEBUG), the code checks whether `SectionNumber` falls within the valid range [1, len(Sections)]. If it is negative or exceeds the number of sections in the file, this error fires, indicating a corrupt or malformed PE binary.","triggerScenarios":"Calling `objfile.Open` on a PE binary followed by `File.Symbols()`, where the PE symbol table contains an entry whose `SectionNumber` is out of range (negative or greater than the section count). This indicates the PE file is corrupt, was produced by a buggy tool, or was truncated.","commonSituations":"Analyzing a corrupt or partially-downloaded Windows `.exe` or `.dll`. Using a binary produced by a non-standard or buggy linker that wrote incorrect section numbers. Post-processing a PE file with a tool that corrupted the symbol table. Reading a PE file that was patched or hex-edited.","solutions":["Verify PE integrity: `dumpbin /symbols <file>` or use a PE analysis tool to check for structural errors.","Rebuild the binary from source with a reliable linker.","If the binary was downloaded, re-download it to rule out truncation.","Use `pev` or similar PE forensics tools to assess the extent of corruption."],"exampleFix":"// before — corrupt PE binary\nf, err := objfile.Open(\"corrupt.exe\")\n_, err := f.Symbols()  // fails: invalid section number\n\n// after — rebuild or re-download\n$ go build -o app.exe ./...\nf, err := objfile.Open(\"app.exe\")\n_, err := f.Symbols()  // succeeds","handlingStrategy":"validation","validationCode":"// Validate PE symbol section numbers\nfunc validatePESymbols(path string) error {\n    f, err := pe.Open(path)\n    if err != nil { return err }\n    defer f.Close()\n    for _, s := range f.Symbols {\n        if s.SectionNumber > 0 && int(s.SectionNumber) > len(f.Sections) {\n            return fmt.Errorf(\"corrupt PE: symbol %s references section %d (max %d)\",\n                s.Name, s.SectionNumber, len(f.Sections))\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"syms, err := f.Symbols()\nif err != nil && strings.Contains(err.Error(), \"invalid section number\") {\n    return fmt.Errorf(\"corrupt PE binary — rebuild or re-download: %w\", err)\n}","preventionTips":["Verify PE structural integrity with dumpbin or pev before analysis.","Rebuild binaries from source when corruption is detected.","Use checksums to detect truncated or modified binaries."],"tags":["pe","windows","symbol-table","corrupt-binary","objfile"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}