{"record":{"id":"b212b8cd0071caf8","repo":"golang/go","slug":"read-namesize-failed-v","errorCode":null,"errorMessage":"read namesize failed: %v","messagePattern":"read namesize failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/buildid/note.go","lineNumber":47,"sourceCode":"func ReadELFNote(filename, name string, typ int32) ([]byte, error) {\n\tf, err := elf.Open(filename)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer f.Close()\n\tfor _, sect := range f.Sections {\n\t\tif sect.Type != elf.SHT_NOTE {\n\t\t\tcontinue\n\t\t}\n\t\tr := sect.Open()\n\t\tfor {\n\t\t\tvar namesize, descsize, noteType int32\n\t\t\terr = binary.Read(r, f.ByteOrder, &namesize)\n\t\t\tif err != nil {\n\t\t\t\tif err == io.EOF {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"read namesize failed: %v\", err)\n\t\t\t}\n\t\t\terr = binary.Read(r, f.ByteOrder, &descsize)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"read descsize failed: %v\", err)\n\t\t\t}\n\t\t\terr = binary.Read(r, f.ByteOrder, &noteType)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"read type failed: %v\", err)\n\t\t\t}\n\t\t\tnoteName, err := readAligned4(r, namesize)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"read name failed: %v\", err)\n\t\t\t}\n\t\t\tdesc, err := readAligned4(r, descsize)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"read desc failed: %v\", err)\n\t\t\t}\n\t\t\tif name == string(noteName) && typ == noteType {","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/buildid/note.go#L29-L65","documentation":"Returned while iterating ELF SHT_NOTE sections in note.go: binary.Read of the 4-byte namesize field failed with a non-EOF error. EOF cleanly terminates the note loop; any other read error (UnexpectedEOF, I/O error) is wrapped as 'read namesize failed'. This indicates the note section is truncated or unreadable.","triggerScenarios":"Calling the ELF note reader (used to extract the Go build ID from a Go-built ELF binary) on a binary whose SHT_NOTE section is shorter than the minimum 12-byte note header, or whose underlying Reader returns an error mid-read.","commonSituations":"Truncated/corrupted Go binaries (interrupted link step, partial download, rsync cut short), object files from a foreign linker, or reading a Go binary built for a different platform whose note layout differs.","solutions":["Rebuild/relink the binary cleanly to eliminate truncation.","Verify file integrity (checksums, `file <bin>`, size vs expected).","Confirm the binary was produced by the Go linker and not stripped/mangled by an external tool.","If on the buildid path, run `go clean -cache` and rebuild."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, err := buildid.ReadFile(bin); err != nil {\n    if strings.Contains(err.Error(), \"read namesize failed\") {\n        // binary note section truncated; rebuild\n        return rebuild(bin)\n    }\n    return err\n}","preventionTips":["Verify binary integrity (checksums) before reading notes.","Rebuild binaries rather than reuse possibly-truncated artifacts.","Validate with `file <bin>` that it is a complete ELF executable."],"tags":["buildid","elf","binary","corruption"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}