{"record":{"id":"c2911d9c72194940","repo":"golang/go","slug":"read-name-failed-v-c2911d","errorCode":null,"errorMessage":"read name failed: %v","messagePattern":"read name failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/link/internal/ld/lib.go","lineNumber":2686,"sourceCode":"\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 := readwithpad(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 := readwithpad(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 string(name) == string(noteName) && typ == noteType {\n\t\t\t\treturn desc, nil\n\t\t\t}\n\t\t}\n\t}\n\treturn nil, nil\n}\n\nfunc findshlib(ctxt *Link, shlib string) string {\n\tif filepath.IsAbs(shlib) {\n\t\treturn shlib\n\t}\n\tfor _, libdir := range ctxt.Libdir {","sourceCodeStart":2668,"sourceCodeEnd":2704,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/link/internal/ld/lib.go#L2668-L2704","documentation":"Once the note header is read, the linker reads `namesize` bytes of name (plus padding to a 4-byte boundary) via `readwithpad`. A failure here means the section claims a name longer than the bytes actually remaining, or the underlying reader errored — the note's name cannot be recovered and the link aborts.","triggerScenarios":"A `namesize` value larger than the remaining section bytes (corrupt or maliciously crafted object); a section whose declared length is shorter than its note header implies; I/O error reading the archive member.","commonSituations":"Corrupted dependency archive; object patched by hand or by a faulty code-generation tool; NFS/network filesystem returning short reads.","solutions":["Rebuild the offending cgo package from source.","Inspect with `readelf -x .note.<name> <obj>` to see if the section bytes match the declared `namesize`.","Replace the object from a trusted source (re-fetch the module, reinstall the C library)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Verify note name lengths fit within their section\nfor obj in $(find build -name '*.o'); do\n  readelf -n \"$obj\" >/dev/null 2>&1 || echo \"note name unreadable: $obj\"\ndone","typeGuard":null,"tryCatchPattern":"set +e\ngo build ./...\nrc=$?\nset -e\n[ $rc -ne 0 ] && { go clean -cache; go build -a ./...; }","preventionTips":["Rebuild objects from source after a C-toolchain change.","Run `readelf -n` over objects in CI.","Avoid transferring objects through text-mode file channels."],"tags":["linker","go-toolchain","elf","cgo","note-section"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}