{"record":{"id":"6fbf1135ac2eb273","repo":"go-delve/delve","slug":"could-not-parse-uleb128-value","errorCode":null,"errorMessage":"Could not parse ULEB128 value","messagePattern":"Could not parse ULEB128 value","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dwarf/leb128/decode.go","lineNumber":31,"sourceCode":"}\n\n// DecodeUnsigned decodes an unsigned Little Endian Base 128\n// represented number.\nfunc DecodeUnsigned(buf Reader) (uint64, uint32) {\n\tvar (\n\t\tresult uint64\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 ULEB128 value\")\n\t\t}\n\t\tlength++\n\n\t\tresult |= uint64((uint(b) & 0x7f) << shift)\n\n\t\t// If high order bit is 1.\n\t\tif b&0x80 == 0 {\n\t\t\tbreak\n\t\t}\n\n\t\tshift += 7\n\t}\n\n\treturn result, length\n}\n\n// DecodeSigned decodes a signed Little Endian Base 128\n// represented number.","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/dwarf/leb128/decode.go#L13-L49","documentation":"leb128.DecodeUnsigned panics with \"Could not parse ULEB128 value\" when the byte reader hits EOF before a terminating byte (high bit 0) is found. A ULEB128 value must end with a byte whose high-order bit is clear; running out of bytes means the encoded value is truncated or the buffer is misaligned. The library treats malformed LEB128 data as a programming error and panics instead of returning an error.","triggerScenarios":"Calling DecodeUnsigned with a buffer that ends while the continuation bit (0x80) is still set — e.g. a truncated DWARF field, a wrong starting offset, or decoding non-LEB128 data as LEB128.","commonSituations":"Corrupt or truncated DWARF sections in binaries/cores; off-by-one offsets when manually walking DWARF structures; attempting to parse data produced by a different encoder at a wrong position.","solutions":["Ensure the byte slice passed to DecodeUnsigned starts exactly at the encoded value and contains its complete bytes.","Validate the enclosing DWARF section is not truncated (check section length vs. offsets).","Wrap the call in defer/recover if parsing untrusted data, converting the panic into an error.","Regenerate or re-obtain the binary/core with intact debug info."],"exampleFix":"// before\nval, _ := leb128.DecodeUnsigned(buf) // panics on truncated input\n// after\nfunc safeDecodeUleb(buf *bytes.Buffer) (val uint64, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"truncated ULEB128: %v\", r)\n\t\t}\n\t}()\n\tval, _ = leb128.DecodeUnsigned(buf)\n\treturn val, nil\n}","handlingStrategy":"try-catch","validationCode":"// Go: verify buffer bounds before decoding ULEB128\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 ULEB128 value\"\n}","typeGuard":null,"tryCatchPattern":"// Go\nfunc decodeU(buf *bytes.Buffer) (v uint64, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"truncated ULEB128: %v\", r)\n\t\t}\n\t}()\n\tv, _ = leb128.DecodeUnsigned(buf)\n\treturn v, nil\n}","preventionTips":["Start decoding exactly at the field's offset","Confirm enclosing DWARF structure lengths before sub-decoding","Never decode ULEB128 from arbitrary/non-DWARF data","Use recover() when parsing untrusted files"],"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"}