go-delve/delve · error
Could not parse SLEB128 value
Error message
Could not parse SLEB128 value
What it means
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.
Source
Thrown at pkg/dwarf/leb128/decode.go:66
// DecodeSigned decodes a signed Little Endian Base 128
// represented number.
func DecodeSigned(buf Reader) (int64, uint32) {
var (
b byte
err error
result int64
shift uint64
length uint32
)
if buf.Len() == 0 {
return 0, 0
}
for {
b, err = buf.ReadByte()
if err != nil {
panic("Could not parse SLEB128 value")
}
length++
result |= (int64(b) & 0x7f) << shift
shift += 7
if b&0x80 == 0 {
break
}
}
if (shift < 8*uint64(length)) && (b&0x40 > 0) {
result |= -(1 << shift)
}
return result, length
}
View on GitHub (pinned to a23773e6c3)
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).
Example fix
// before
v, _ := leb128.DecodeSigned(buf) // panics if truncated
// after
func safeDecodeSleb(buf *bytes.Buffer) (v int64, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("truncated SLEB128: %v", r)
}
}()
v, _ = leb128.DecodeSigned(buf)
return v, nil
} Defensive patterns
Strategy: try-catch
Validate before calling
// Go: verify buffer bounds before decoding SLEB128
func hasTerminator(b []byte) bool {
for _, c := range b {
if c&0x80 == 0 { return true }
}
return false // would trigger "Could not parse SLEB128 value"
} Try / catch
// Go
func decodeS(buf *bytes.Buffer) (v int64, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("truncated SLEB128: %v", r)
}
}()
v, _ = leb128.DecodeSigned(buf)
return v, nil
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Truncated .debug_line/.debug_info sections; manual DWARF parsing with an incorrect offset; parsing a value that was actually ULEB128-encoded at that position.
Related errors
- Could not parse ULEB128 value
- panic(err)
- Could not read from instruction buffer
- Could not unread byte
- Could not read byte
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/6ee02f302a424f27.
Report an issue: GitHub.