{"record":{"id":"6ee02f302a424f27","repo":"go-delve/delve","slug":"could-not-parse-sleb128-value","errorCode":null,"errorMessage":"Could not parse SLEB128 value","messagePattern":"Could not parse SLEB128 value","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dwarf/leb128/decode.go","lineNumber":66,"sourceCode":"// DecodeSigned decodes a signed Little Endian Base 128\n// represented number.\nfunc DecodeSigned(buf Reader) (int64, uint32) {\n\tvar (\n\t\tb      byte\n\t\terr    error\n\t\tresult int64\n\t\tshift  uint64\n\t\tlength uint32\n\t)\n\n\tif buf.Len() == 0 {\n\t\treturn 0, 0\n\t}\n\n\tfor {\n\t\tb, err = buf.ReadByte()\n\t\tif err != nil {\n\t\t\tpanic(\"Could not parse SLEB128 value\")\n\t\t}\n\t\tlength++\n\n\t\tresult |= (int64(b) & 0x7f) << shift\n\t\tshift += 7\n\t\tif b&0x80 == 0 {\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif (shift < 8*uint64(length)) && (b&0x40 > 0) {\n\t\tresult |= -(1 << shift)\n\t}\n\n\treturn result, length\n}\n","sourceCodeStart":48,"sourceCodeEnd":83,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/dwarf/leb128/decode.go#L48-L83","documentation":"leb128.DecodeSigned panics with \"Could not parse SLEB128 value\" when the reader is exhausted before a byte with the continuation bit clear terminates the SLEB128 encoding. This means the signed LEB128 field is truncated or the read position is wrong. Like its unsigned counterpart, the decoder treats this as a fatal data-integrity error and panics.","triggerScenarios":"Calling DecodeSigned on a buffer that ends mid-encoding (continuation bit 0x80 still set on the last available byte), or pointing the buffer at non-SLEB128 data.","commonSituations":"Truncated .debug_line/.debug_info sections; manual DWARF parsing with an incorrect offset; parsing a value that was actually ULEB128-encoded at that position.","solutions":["Confirm the buffer starts at the exact SLEB128 field and includes all its bytes.","Check the parent DWARF structure's lengths/offsets for a prior misparse that left the reader misaligned.","Guard untrusted-input parsing with defer/recover to convert the panic into an error.","Replace or repair the corrupted debug sections (rebuild with debug info)."],"exampleFix":"// before\nv, _ := leb128.DecodeSigned(buf) // panics if truncated\n// after\nfunc safeDecodeSleb(buf *bytes.Buffer) (v int64, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"truncated SLEB128: %v\", r)\n\t\t}\n\t}()\n\tv, _ = leb128.DecodeSigned(buf)\n\treturn v, nil\n}","handlingStrategy":"try-catch","validationCode":"// Go: verify buffer bounds before decoding SLEB128\nfunc hasTerminator(b []byte) bool {\n\tfor _, c := range b {\n\t\tif c&0x80 == 0 { return true }\n\t}\n\treturn false // would trigger \"Could not parse SLEB128 value\"\n}","typeGuard":null,"tryCatchPattern":"// Go\nfunc decodeS(buf *bytes.Buffer) (v int64, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"truncated SLEB128: %v\", r)\n\t\t}\n\t}()\n\tv, _ = leb128.DecodeSigned(buf)\n\treturn v, nil\n}","preventionTips":["Confirm the field is SLEB128 (signed), not ULEB128, before decoding","Track offsets carefully in manual DWARF walks to avoid misalignment","Validate section truncation before parsing sub-structures","Recover() around decoders for untrusted data"],"tags":["dwarf","leb128","panic","truncated-data"],"backgroundTag":"malformed-dwarf-data","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}