{"record":{"id":"8e8768d3e24ccad1","repo":"go-delve/delve","slug":"negative-array-length","errorCode":null,"errorMessage":"Negative array length","messagePattern":"Negative array length","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/variables.go","lineNumber":1728,"sourceCode":"\t\tnewStructType.Field[i] = field\n\t}\n\n\tv.RealType = &godwarf.ChanType{\n\t\tTypedefType: godwarf.TypedefType{\n\t\t\tCommonType: chanType.TypedefType.CommonType,\n\t\t\tType:       pointerTo(newStructType, v.bi.Arch),\n\t\t},\n\t\tElemType: chanType.ElemType,\n\t}\n}\n\nfunc (v *Variable) loadArrayValues(recurseLevel int, cfg LoadConfig) {\n\tif v.Unreadable != nil {\n\t\treturn\n\t}\n\tif v.Len < 0 {\n\t\t//lint:ignore ST1005 backwards compatibility\n\t\tv.Unreadable = errors.New(\"Negative array length\")\n\t\treturn\n\t}\n\tif v.Base == 0 && v.Len > 0 {\n\t\tv.Unreadable = errors.New(\"non-zero length array with nil base\")\n\t\treturn\n\t}\n\n\tcount := v.Len\n\t// Cap number of elements\n\tif (v.Flags&variableTrustLen == 0) && (count > int64(cfg.MaxArrayValues)) {\n\t\tcount = int64(cfg.MaxArrayValues)\n\t}\n\tif v.Base+uint64(v.stride*count) < v.Base {\n\t\tv.Unreadable = fmt.Errorf(\"bad array base address %#x\", v.Base)\n\t\treturn\n\t}\n\n\tif v.stride < maxArrayStridePrefetch {","sourceCodeStart":1710,"sourceCodeEnd":1746,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/variables.go#L1710-L1746","documentation":"loadArrayValues refuses to read an array/slice whose Len field is negative. A negative length is impossible for real Go arrays/slices and indicates corrupted memory, bad type interpretation, or a misread slice header. The variable is marked unreadable with this exact (capitalized, for backwards compatibility) message.","triggerScenarios":"Evaluating a slice/array whose slice header (data pointer, len, cap) was read as garbage — e.g. reading through an invalid address, evaluating a non-slice as a slice, or memory corruption in the debuggee.","commonSituations":"Inspecting slices in corrupted heap regions, evaluating unsafe-cast values, debugging crashes where the slice header itself was overwritten, or stale registers after a crash point.","solutions":["Inspect the slice header fields individually (data ptr, len, cap) with `print` to confirm the length value.","Re-evaluate after stepping to a state where the slice is fully initialized.","Verify the variable's address is valid (not reading garbage memory).","If persistent, check the debuggee for memory corruption (this may be a real bug in your program)."],"exampleFix":"// before (evaluating possibly-garbage header as slice)\nprint(*(*[]int)(unsafe.Pointer(&garbage)))\n// after\nif lenHeader >= 0 { print(slice) } else { print(\"invalid slice header\") }","handlingStrategy":"validation","validationCode":"if v.Len < 0 {\n    // do not call array-loading APIs on this variable\n    return\n}","typeGuard":null,"tryCatchPattern":"if v.Unreadable != nil && strings.Contains(v.Unreadable.Error(), \"Negative array length\") {\n    // treat as unreadable; inspect the raw header manually\n    return\n}","preventionTips":["Validate slice headers (0 <= len <= cap) before evaluating casted memory","Avoid evaluating slices from uninitialized or corrupted memory regions","Re-evaluate variables only at program points where they are in scope and initialized"],"tags":["debugger","arrays","slices"],"backgroundTag":"negative-array-length","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}