{"record":{"id":"b81bb7ad12023de8","repo":"go-delve/delve","slug":"len-must-be-less-than-or-equal-to-d","errorCode":null,"errorMessage":"len must be less than or equal to %d","messagePattern":"len must be less than or equal to (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/rpc2/server.go","lineNumber":1012,"sourceCode":"}\n\n// ExamineMemoryIn holds the arguments of ExamineMemory\ntype ExamineMemoryIn struct {\n\tAddress uint64\n\tLength  int\n}\n\n// ExaminedMemoryOut holds the return values of ExamineMemory\ntype ExaminedMemoryOut struct {\n\tMem            []byte\n\tIsLittleEndian bool\n}\n\nconst ExamineMemoryLengthLimit = 1 << 16\n\nfunc (s *RPCServer) ExamineMemory(arg ExamineMemoryIn, out *ExaminedMemoryOut) error {\n\tif arg.Length > ExamineMemoryLengthLimit {\n\t\treturn fmt.Errorf(\"len must be less than or equal to %d\", ExamineMemoryLengthLimit)\n\t}\n\tMem, err := s.debugger.ExamineMemory(arg.Address, arg.Length)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tout.Mem = Mem\n\tout.IsLittleEndian = true //TODO: get byte order from debugger.target.BinInfo().Arch\n\n\treturn nil\n}\n\ntype StopRecordingIn struct {\n}\n\ntype StopRecordingOut struct {\n}\n","sourceCodeStart":994,"sourceCodeEnd":1030,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/rpc2/server.go#L994-L1030","documentation":"ExamineMemory enforces a hard cap of ExamineMemoryLengthLimit (1<<16 = 65536) bytes per request and throws this error when arg.Length exceeds it. The limit protects the debugger and client from absurdly large single reads over the RPC channel.","triggerScenarios":"Calling RPCClient.ExamineMemory with ExamineMemoryIn.Length greater than 65536, e.g. requesting a multi-megabyte region in one call to dump a large buffer or an entire memory mapping.","commonSituations":"Dumping large heap allocations or file-mapped regions from tooling; clients with hardcoded large defaults; misinterpreting Length as bytes-available rather than request size.","solutions":["Chunk the read: loop with Length <= 65536 and increment Address by the chunk size","Clamp the request to min(desired, rpc2.ExamineMemoryLengthLimit) before calling","For large dumps, read the region in pages and concatenate results client-side","Check the constant at runtime (rpc2.ExamineMemoryLengthLimit) instead of hardcoding 65536 in case it changes"],"exampleFix":"// before\ndata, err := client.ExamineMemory(rpc2.ExamineMemoryIn{Address: addr, Length: 1 << 20}) // too large\n// after\nconst chunk = 1 << 16\nvar data []byte\nfor off := uint64(0); off < 1<<20; off += chunk {\n    out, err := client.ExamineMemory(rpc2.ExamineMemoryIn{Address: addr + off, Length: chunk})\n    if err != nil {\n        return err\n    }\n    data = append(data, out.Mem...)\n}","handlingStrategy":"validation","validationCode":"func clampLength(n uint32) uint32 {\n    if n > rpc2.ExamineMemoryLengthLimit {\n        return rpc2.ExamineMemoryLengthLimit\n    }\n    return n\n}\n// use: Length: clampLength(requested)","typeGuard":null,"tryCatchPattern":"out, err := client.ExamineMemory(rpc2.ExamineMemoryIn{Address: addr, Length: n})\nif err != nil && strings.Contains(err.Error(), \"len must be less than or equal to\") {\n    return fmt.Errorf(\"request %d bytes exceeds %d-byte limit; chunk the read\", n, rpc2.ExamineMemoryLengthLimit)\n}","preventionTips":["Always chunk large memory dumps into <=64KiB reads","Reference rpc2.ExamineMemoryLengthLimit instead of hardcoding the value","Sanitize user-supplied dump sizes at the tool boundary","Accumulate chunked reads into one buffer when a full region is needed"],"tags":["rpc","memory","limit","delve"],"backgroundTag":"request-limit-exceeded","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}