{"record":{"id":"808dfb8ffb5731b9","repo":"golang/go","slug":"read-descsize-failed-v-808dfb","errorCode":null,"errorMessage":"read descsize failed: %v","messagePattern":"read descsize failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/link/internal/ld/lib.go","lineNumber":2678,"sourceCode":"\nfunc readnote(f *elf.File, name []byte, typ int32) ([]byte, error) {\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 := 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}","sourceCodeStart":2660,"sourceCodeEnd":2696,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/link/internal/ld/lib.go#L2660-L2696","documentation":"After reading a note's `namesize`, the linker reads the 4-byte `descsize` field that gives the descriptor length. A failure here (other than the EOF that terminates the section) means the note record is truncated mid-header: namesize was consumed but the descriptor-length word is missing or unreadable, so the note cannot be sized and the link aborts.","triggerScenarios":"A `SHT_NOTE` section whose total length is not a multiple of the note header (12 bytes), leaving a stray `namesize` with no `descsize`; an archive member truncated by a failed write; an object emitted by a tool that writes a non-conforming note record.","commonSituations":"Truncated `.o` from an interrupted `cc` compile; corrupted build cache; object hand-edited or transferred with size corruption (e.g. FTP text-mode conversion).","solutions":["Rebuild all cgo/C objects with `-a` to regenerate archives.","Validate the object: `readelf -n` should list notes without error; if it errors, the object is corrupt.","Re-acquire the object from a known-good source (re-`go mod download`, reinstall the C dependency)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Confirm note sections parse cleanly (no truncated headers)\nfor obj in $(find build -name '*.o'); do\n  readelf -n \"$obj\" >/dev/null 2>&1 || echo \"bad notes: $obj\"\ndone","typeGuard":null,"tryCatchPattern":"set +e\ngo build ./...\nrc=$?\nset -e\n[ $rc -ne 0 ] && { go clean -cache; go build -a ./...; }","preventionTips":["Ensure builds are not interrupted (no OOM-kill, no disk-full).","Rebuild objects from source rather than copying `.a` files between machines.","Validate ELF notes with `readelf -n` in CI."],"tags":["linker","go-toolchain","elf","cgo","note-section"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}