{"record":{"id":"b39da840e20593b4","repo":"nats-io/nats-server","slug":"processroutedmsgargs-bad-or-missing-size-s","errorCode":null,"errorMessage":"processRoutedMsgArgs Bad or Missing Size: '%s'","messagePattern":"processRoutedMsgArgs Bad or Missing Size: '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/route.go","lineNumber":446,"sourceCode":"\t\t\tc.pa.reply = args[3]\n\t\tcase '|':\n\t\t\tc.pa.reply = nil\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"processRoutedMsgArgs Bad or Missing Reply Indicator: '%s'\", args[2])\n\t\t}\n\t\t// Grab size.\n\t\tc.pa.szb = args[len(args)-1]\n\t\tc.pa.size = parseSize(c.pa.szb)\n\n\t\t// Grab queue names.\n\t\tif c.pa.reply != nil {\n\t\t\tc.pa.queues = args[4 : len(args)-1]\n\t\t} else {\n\t\t\tc.pa.queues = args[3 : len(args)-1]\n\t\t}\n\t}\n\tif c.pa.size < 0 {\n\t\treturn fmt.Errorf(\"processRoutedMsgArgs Bad or Missing Size: '%s'\", args)\n\t}\n\n\t// Common ones processed after check for arg length\n\tc.pa.account = args[0]\n\tc.pa.subject = args[1]\n\tif len(an) > 0 {\n\t\tc.pa.pacache = c.pa.subject\n\t} else {\n\t\tc.pa.pacache = arg[:len(args[0])+len(args[1])+1]\n\t}\n\treturn nil\n}\n\n// processInboundRoutedMsg is called to process an inbound msg from a route.\nfunc (c *client) processInboundRoutedMsg(msg []byte) {\n\t// Update statistics\n\tc.in.msgs++\n\t// The msg includes the CR_LF, so pull back out for accounting.","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/route.go#L428-L464","documentation":"After parsing a routed MSG's size field, the server checks that the resulting size is non-negative. parseSize returns -1 for a non-numeric or negative size value, so a bad or missing final size field triggers this error. It protects the server from allocating based on garbage lengths.","triggerScenarios":"Final arg of a routed MSG is not a valid non-negative integer (e.g. 'abc', '-5', or empty), causing parseSize to return -1.","commonSituations":"Corrupt cluster traffic, custom publishers writing wrong size fields, off-by-one in hand-built protocol emitters that put a queue name where the size belongs, or truncated frames after network errors.","solutions":["Ensure the last field of the routed MSG line is the decimal byte size of the payload","Fix the emitter to compute size as len(payload) exactly","Trace the raw protocol line to see which sender produced the malformed frame","Check route/TLS links for corruption and keep cluster servers on compatible versions"],"exampleFix":"// before\n\"MSG foo + reply 5 abc\\r\\n\" // 'abc' where size should be\n// after\n\"MSG foo + reply 5\\r\\n\" + payload","handlingStrategy":"validation","validationCode":"// Validate the size field parses to a non-negative integer before sending\nsize, err := strconv.Atoi(lastField)\nif err != nil || size < 0 {\n    return fmt.Errorf(\"bad size field %q\", lastField)\n}\nif size != len(payload) {\n    return fmt.Errorf(\"size %d != payload len %d\", size, len(payload))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute sizes with len() instead of hand-counting bytes","Keep size as the final field of the MSG line","Alert on server-side bad-size parse errors to catch broken emitters quickly"],"tags":["nats-server","protocol","routing","message-parsing"],"backgroundTag":"invalid-payload-size","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}