{"record":{"id":"40820beffdf9278c","repo":"go-delve/delve","slug":"invalid-length-d","errorCode":null,"errorMessage":"invalid length: %d","messagePattern":"invalid length: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/variables.go","lineNumber":1542,"sourceCode":"func readStringInfo(mem MemoryReadWriter, arch *Arch, addr uint64, typ *godwarf.StringType) (uint64, int64, error) {\n\t// string data structure is always two ptrs in size. Addr, followed by len\n\t// https://research.swtch.com/godata\n\n\tmem = cacheMemory(mem, addr, arch.PtrSize()*2)\n\n\tvar strlen int64\n\tvar outaddr uint64\n\tvar err error\n\n\tfor _, field := range typ.StructType.Field {\n\t\tswitch field.Name {\n\t\tcase \"len\":\n\t\t\tstrlen, err = readIntRaw(mem, addr+uint64(field.ByteOffset), int64(arch.PtrSize()))\n\t\t\tif err != nil {\n\t\t\t\treturn 0, 0, fmt.Errorf(\"could not read string len %s\", err)\n\t\t\t}\n\t\t\tif strlen < 0 {\n\t\t\t\treturn 0, 0, fmt.Errorf(\"invalid length: %d\", strlen)\n\t\t\t}\n\t\tcase \"str\":\n\t\t\toutaddr, err = readUintRaw(mem, addr+uint64(field.ByteOffset), int64(arch.PtrSize()))\n\t\t\tif err != nil {\n\t\t\t\treturn 0, 0, fmt.Errorf(\"could not read string pointer %s\", err)\n\t\t\t}\n\t\t\tif addr == 0 {\n\t\t\t\treturn 0, 0, nil\n\t\t\t}\n\t\t}\n\t}\n\n\treturn outaddr, strlen, nil\n}\n\nfunc readStringValue(mem MemoryReadWriter, addr uint64, strlen int64, cfg LoadConfig) (string, error) {\n\tif strlen == 0 {\n\t\treturn \"\", nil","sourceCodeStart":1524,"sourceCodeEnd":1560,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/variables.go#L1524-L1560","documentation":"After reading a string's `len` field from target memory, the value was negative. Go strings can never have negative lengths, so Delve rejects the header as corrupt rather than reading (or clamping) the string. This is a consistency check inside string header loading.","triggerScenarios":"Evaluating a string whose memory-resident `len` word is negative, i.e. the high bit of the pointer-size integer is set; typically means the header bytes were misread or the memory does not actually contain a string header.","commonSituations":"Reading misaligned or corrupted stack memory; evaluating through an incorrect expression that lands on non-string bytes; unsafe code that overwrote a string header.","solutions":["Verify the expression actually addresses a string (print the parent struct/value).","Inspect raw memory at the address to confirm header contents.","If memory is corrupted, find the code that overwrote it (this is a bug in the debugged program)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the expression targets a real string:\n// (dlv) print parent.strField   // then inspect len\n// A negative len means the memory is not a valid string header.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Confirm the evaluated address actually holds a string header (print the parent).","Treat negative len as a sign of memory corruption in the debugged program.","Avoid evaluating through stale or miscomputed pointer arithmetic."],"tags":["debugger","go","string","corrupt-memory"],"backgroundTag":"invalid-string-length","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}