golang/go · error

read descsize failed

Error message

read descsize failed: %v

What it means

Returned after successfully reading namesize when binary.Read of the descsize field fails (non-EOF). The ELF note header is namesize(4) + descsize(4) + type(4); failing on the second word means the section ended prematurely between fields. Wrapped and propagated from the note reader.

Solutions

  1. Rebuild the binary from source.
  2. Clean the build cache: `go clean -cache`.
  3. Check the binary was completely written (size, checksums, `file <bin>`).
  4. Avoid stripping or post-processing the binary with tools that truncate note sections.
Defensive patterns

Strategy: try-catch

Try / catch

if _, err := buildid.ReadFile(bin); err != nil {
    if strings.Contains(err.Error(), "read descsize failed") {
        return rebuild(bin) // truncated ELF note header
    }
    return err
}

Prevention

When it happens

Trigger: Reading an ELF note section whose header is at least 4 bytes but fewer than 8, so namesize parses but descsize does not. Produced by the same code path as error 1227 when corruption lands mid-header.

Common situations: Truncated ELF note sections in partially linked or partially downloaded Go binaries; corrupt object cache entries; hand-modified binaries.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/1e302bce0dd8f528. Report an issue: GitHub.

Appendix: source

Thrown at src/cmd/internal/buildid/note.go:51

	}
	defer f.Close()
	for _, sect := range f.Sections {
		if sect.Type != elf.SHT_NOTE {
			continue
		}
		r := sect.Open()
		for {
			var namesize, descsize, noteType int32
			err = binary.Read(r, f.ByteOrder, &namesize)
			if err != nil {
				if err == io.EOF {
					break
				}
				return nil, fmt.Errorf("read namesize failed: %v", err)
			}
			err = binary.Read(r, f.ByteOrder, &descsize)
			if err != nil {
				return nil, fmt.Errorf("read descsize failed: %v", err)
			}
			err = binary.Read(r, f.ByteOrder, &noteType)
			if err != nil {
				return nil, fmt.Errorf("read type failed: %v", err)
			}
			noteName, err := readAligned4(r, namesize)
			if err != nil {
				return nil, fmt.Errorf("read name failed: %v", err)
			}
			desc, err := readAligned4(r, descsize)
			if err != nil {
				return nil, fmt.Errorf("read desc failed: %v", err)
			}
			if name == string(noteName) && typ == noteType {
				return desc, nil
			}
		}
	}

View on GitHub (pinned to b6b368adc5)