{"record":{"id":"83a145b9a84887f3","repo":"go-delve/delve","slug":"bad-address-size","errorCode":null,"errorMessage":"bad address size","messagePattern":"bad address size","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dwarf/loclist/dwarf2_loclist.go","lineNumber":93,"sourceCode":"func (rdr *Dwarf2Reader) read(sz int) []byte {\n\tr := rdr.data[rdr.cur : rdr.cur+sz]\n\trdr.cur += sz\n\treturn r\n}\n\nfunc (rdr *Dwarf2Reader) oneAddr() uint64 {\n\tswitch rdr.ptrSz {\n\tcase 4:\n\t\taddr := binary.LittleEndian.Uint32(rdr.read(rdr.ptrSz))\n\t\tif addr == ^uint32(0) {\n\t\t\treturn ^uint64(0)\n\t\t}\n\t\treturn uint64(addr)\n\tcase 8:\n\t\taddr := binary.LittleEndian.Uint64(rdr.read(rdr.ptrSz))\n\t\treturn addr\n\tdefault:\n\t\tpanic(\"bad address size\")\n\t}\n}\n\n// Entry represents a single entry in the loclist section.\ntype Entry struct {\n\tLowPC, HighPC uint64\n\tInstr         []byte\n}\n\n// BaseAddressSelection returns true if entry.highpc should\n// be used as the base address for subsequent entries.\nfunc (e *Entry) BaseAddressSelection() bool {\n\treturn e.LowPC == ^uint64(0)\n}\n","sourceCodeStart":75,"sourceCodeEnd":108,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/dwarf/loclist/dwarf2_loclist.go#L75-L108","documentation":"The DWARF2 loclist reader (pkg/dwarf/loclist/dwarf2_loclist.go) panics with \"bad address size\" when the address size used to read a loclist entry's low/high PC is neither 4 nor 8 bytes. Address sizes must match the target architecture (32- or 64-bit); any other value means the DWARF metadata (address_size in the CU header / ptrSz) is wrong or corrupted. This is a fail-fast guard against nonsensical metadata.","triggerScenarios":"Calling loclist Next() (via oneAddr) when rdr.addrSize (derived from CU address_size or ptrSz) has a value other than 4 or 8 — e.g. corrupted address_size field, wrong binaryinfo setup, or foreign/arch-mismatched DWARF.","commonSituations":"Debugging a binary compiled for a different architecture than assumed; corrupted DWARF sections in core dumps; toolchains emitting nonstandard address_size values.","solutions":["Confirm the ELF header's architecture matches the DWARF address_size in the compile unit; debug the correct target binary.","Inspect the CU header's address_size field for corruption; re-obtain or rebuild the binary with debug info.","Check where rdr.ptrSz/addrSize is initialized in Delve's bininfo and that the correct architecture is detected.","If reading untrusted files, wrap loclist parsing in recover() and return a descriptive error."],"exampleFix":"// before\ndefault:\n\tpanic(\"bad address size\")\n// after\ndefault:\n\treturn 0, fmt.Errorf(\"unsupported DWARF address size %d\", size) // propagate instead of panic","handlingStrategy":"validation","validationCode":"// Go: validate address size before reading loclist entries\nif addrSize != 4 && addrSize != 8 {\n\treturn fmt.Errorf(\"unsupported address size %d\", addrSize)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match the debugged binary's architecture to the DWARF address_size","Validate the CU header address_size (must be 4 or 8) before loclist reads","Do not cross-read DWARF from a different architecture's image","Wrap loclist parsing in recover() for untrusted files"],"tags":["dwarf","loclist","architecture","panic"],"backgroundTag":"malformed-dwarf-data","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}