{"record":{"id":"fe5fdd9f3985ca05","repo":"nats-io/nats-server","slug":"processpub-bad-or-missing-size-q","errorCode":null,"errorMessage":"processPub Bad or Missing Size: %q","messagePattern":"processPub Bad or Missing Size: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/client.go","lineNumber":2991,"sourceCode":"\n\tc.pa.arg = arg\n\tswitch len(args) {\n\tcase 2:\n\t\tc.pa.subject = args[0]\n\t\tc.pa.reply = nil\n\t\tc.pa.size = parseSize(args[1])\n\t\tc.pa.szb = args[1]\n\tcase 3:\n\t\tc.pa.subject = args[0]\n\t\tc.pa.reply = args[1]\n\t\tc.pa.size = parseSize(args[2])\n\t\tc.pa.szb = args[2]\n\tdefault:\n\t\treturn fmt.Errorf(\"processPub Parse Error: %q\", arg)\n\t}\n\t// If number overruns an int64, parseSize() will have returned a negative value\n\tif c.pa.size < 0 {\n\t\treturn fmt.Errorf(\"processPub Bad or Missing Size: %q\", arg)\n\t}\n\tmaxPayload := atomic.LoadInt32(&c.mpay)\n\t// Use int64() to avoid int32 overrun...\n\tif maxPayload != jwt.NoLimit && int64(c.pa.size) > int64(maxPayload) {\n\t\tc.maxPayloadViolation(c.pa.size, maxPayload)\n\t\treturn ErrMaxPayload\n\t}\n\tif c.opts.Pedantic && !IsValidLiteralSubject(bytesToString(c.pa.subject)) {\n\t\tc.sendErr(\"Invalid Publish Subject\")\n\t}\n\treturn nil\n}\n\nfunc splitArg(arg []byte) [][]byte {\n\ta := [MAX_MSG_ARGS][]byte{}\n\targs := a[:0]\n\tstart := -1\n\tfor i, b := range arg {","sourceCodeStart":2973,"sourceCodeEnd":3009,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/client.go#L2973-L3009","documentation":"The size field of a PUB operation parsed to a negative value. parseSize() returns -1 when the token is missing, non-numeric, negative, or overflows int64, so the server rejects the publish and closes the connection.","triggerScenarios":"Client sends `PUB <subject> <size>` (or with reply) where size is non-numeric or overflows int64, e.g. `PUB foo abc` or `PUB foo 99999999999999999999`, so c.pa.size < 0.","commonSituations":"Client computing payload length with a signed/overflowing type, passing -1 as a sentinel size, corrupted frames from the network.","solutions":["Fix the client to send the actual payload byte length as a non-negative decimal integer","Check the client code for signed-size or int64-overflow calculations on large payloads","Capture traffic/debug logs to identify the malformed PUB line and offending client"],"exampleFix":"// before\nPUB subj -1\n\n// after\nPUB subj 5\nhello","handlingStrategy":"validation","validationCode":"size := len(payload)\nif size < 0 || size > math.MaxInt32 {\n    return errors.New(\"PUB size out of range\")\n}\nframe := fmt.Sprintf(\"PUB %s %d\\r\\n\", subject, size)","typeGuard":"func isNonNegativeSize(token string) (int64, bool) {\n    n, err := strconv.ParseInt(token, 10, 64)\n    return n, err == nil && n >= 0\n}","tryCatchPattern":null,"preventionTips":["Send len(payload) as the size, computed as unsigned/int64 then bounded","Guard against int64 overflow for very large payloads","Never use -1 as a size sentinel"],"tags":["protocol","parsing","overflow"],"backgroundTag":"nats-protocol-parse-error","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}