{"record":{"id":"560e3c380be7992e","repo":"golang/go","slug":"pe-file-format-not-recognized","errorCode":null,"errorMessage":"pe file format not recognized","messagePattern":"pe file format not recognized","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/objfile/pe.go","lineNumber":213,"sourceCode":"\tcase pe.IMAGE_FILE_MACHINE_ARM64:\n\t\treturn \"arm64\"\n\tdefault:\n\t\treturn \"\"\n\t}\n}\n\nfunc (f *peFile) loadAddress() (uint64, error) {\n\treturn f.imageBase()\n}\n\nfunc (f *peFile) imageBase() (uint64, error) {\n\tswitch oh := f.pe.OptionalHeader.(type) {\n\tcase *pe.OptionalHeader32:\n\t\treturn uint64(oh.ImageBase), nil\n\tcase *pe.OptionalHeader64:\n\t\treturn oh.ImageBase, nil\n\tdefault:\n\t\treturn 0, fmt.Errorf(\"pe file format not recognized\")\n\t}\n}\n\nfunc (f *peFile) dwarf() (*dwarf.Data, error) {\n\treturn f.pe.DWARF()\n}\n","sourceCodeStart":195,"sourceCodeEnd":220,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/objfile/pe.go#L195-L220","documentation":"imageBase() reads the PE optional header to recover the image load base address, switching on *pe.OptionalHeader32 and *pe.OptionalHeader64. Any other optional-header type (or nil/missing) means the file is not a recognizable PE executable, so the loader declines to guess. This is the loadAddress path used when computing virtual addresses for symbols.","triggerScenarios":"Calling peFile.loadAddress() (or any code that needs the image base) on a pe.File whose OptionalHeader is neither *pe.OptionalHeader32 nor *pe.OptionalHeader64.","commonSituations":"A non-PE file was opened through the PE code path (wrong format detection), a truncated/corrupted PE, or an unusual PE-like image (EFI/ROM) with headers the debug/pe package does not model.","solutions":["Verify the file is actually a PE/COFF executable (run 'file <binary>').","Rebuild the binary; if it is genuinely PE, ensure it was not truncated.","Let the objfile format detector pick the right backend rather than forcing PE."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before treating a file as PE, confirm its magic.\n// import \"debug/pe\"\n// f, err := pe.Open(path)\n// if err != nil { /* not PE */ }\n// if f.OptionalHeader == nil { /* not a recognizable PE */ }","typeGuard":null,"tryCatchPattern":"// base, err := pf.loadAddress()\n// if err != nil {\n//     // 'pe file format not recognized' -> wrong backend or corrupt PE\n//     return 0, err\n// }","preventionTips":["Use 'file <binary>' to confirm PE before running PE-specific tooling.","Let the objfile format detector choose the backend automatically.","Rebuild suspect Windows binaries rather than reusing old artifacts."],"tags":["pe","windows","binary","objfile","load-address"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}