{"record":{"id":"3a63565588c55a6a","repo":"go-delve/delve","slug":"panic-err","errorCode":null,"errorMessage":"panic(err)","messagePattern":"panic\\(err\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dwarf/frame/table.go","lineNumber":288,"sourceCode":"\nfunc advanceloc2(frame *FrameContext) {\n\tvar delta uint16\n\tbinary.Read(frame.buf, frame.order, &delta)\n\n\tframe.loc += uint64(delta) * frame.codeAlignment\n}\n\nfunc advanceloc4(frame *FrameContext) {\n\tvar delta uint32\n\tbinary.Read(frame.buf, frame.order, &delta)\n\n\tframe.loc += uint64(delta) * frame.codeAlignment\n}\n\nfunc offset(frame *FrameContext) {\n\tb, err := frame.buf.ReadByte()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tvar (\n\t\treg       = b & low_6_offset\n\t\toffset, _ = leb128.DecodeUnsigned(frame.buf)\n\t)\n\n\tframe.Regs[uint64(reg)] = DWRule{Offset: int64(offset) * frame.dataAlignment, Rule: RuleOffset}\n}\n\nfunc restore(frame *FrameContext) {\n\tb, err := frame.buf.ReadByte()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\treg := uint64(b & low_6_offset)\n\toldrule, ok := frame.initialRegs[reg]","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/dwarf/frame/table.go#L270-L306","documentation":"The DWARF CFI opcode interpreter in pkg/dwarf/frame/table.go calls panic(err) when the underlying byte buffer returns an error while reading an opcode operand in the `offset` (DW_CFA_offset-like) instruction handler. This means the CFI instruction stream was truncated or the buffer was exhausted mid-instruction. It signals corrupt, truncated, or improperly parsed .eh_frame/.debug_frame data rather than an expected runtime condition.","triggerScenarios":"Executing the `offset` CFI opcode handler when frame.buf.ReadByte() fails because the instruction stream ends before the register byte (and following ULEB128 offset) can be fully read — e.g. a truncated .debug_frame section, a misaligned instruction stream, or advancing a reader past its end.","commonSituations":"Parsing core dumps or stripped binaries with damaged/truncated DWARF sections; a length/count mismatch upstream that slices the instruction buffer too short; hand-crafted or fuzzed ELF files fed to the frame parser.","solutions":["Verify the binary/core file is complete and its .eh_frame/.debug_frame sections are not truncated (re-obtain the file or re-dump the core).","Check the upstream code that computes the instruction length/buffer for the frame entry; a wrong length makes buf end mid-instruction.","Update Delve: newer versions may return an error instead of panicking on malformed CFI data.","If parsing untrusted binaries, wrap CFI parsing in recover() and surface a descriptive error."],"exampleFix":"// before (table.go)\nb, err := frame.buf.ReadByte()\nif err != nil {\n\tpanic(err)\n}\n// after\ntype frameParseError struct{ msg string; err error }\nfunc offset(frame *FrameContext) (err error) {\n\tb, err := frame.buf.ReadByte()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"malformed CFI: reading offset opcode: %w\", err)\n\t}\n\treturn nil\n}","handlingStrategy":"try-catch","validationCode":"// Go: check section completeness before parsing CFI\nif len(debugFrameData) == 0 || uint64(len(debugFrameData)) < fdeLength {\n\treturn errors.New(\"truncated .debug_frame data\")\n}","typeGuard":null,"tryCatchPattern":"// Go\ngo func() {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"malformed CFI instruction stream: %v\", r)\n\t\t}\n\t}()\n\tbuildFrameTable(buf)\n}()","preventionTips":["Only parse complete, unmodified binaries and core dumps","Validate section lengths against file size before parsing","Keep Delve updated — panic-on-malformed may become error returns","Recover() around frame table construction for untrusted inputs"],"tags":["dwarf","panic","corrupt-data","cfi"],"backgroundTag":"malformed-dwarf-data","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}