{"record":{"id":"2aae3416c436ddbf","repo":"hashicorp/nomad","slug":"total-length-of-the-prefix-message-is-out-of-range","errorCode":null,"errorMessage":"Total length of the prefix message is out of range: %d","messagePattern":"Total length of the prefix message is out of range: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/testlog/testlog.go","lineNumber":110,"sourceCode":"\tprefix []byte\n}\n\n// Write to stdout with a prefix per call containing non-whitespace characters.\nfunc (w *prefixStderr) Write(p []byte) (int, error) {\n\tif len(p) == 0 {\n\t\treturn 0, nil\n\t}\n\n\t// Skip prefix if only writing whitespace\n\tif len(bytes.TrimSpace(p)) == 0 {\n\t\treturn os.Stderr.Write(p)\n\t}\n\n\t// decrease likely hood of partial line writes that may mess up test\n\t// indicator success detection\n\ttotalLength := len(w.prefix) + len(p)\n\tif totalLength < 0 || totalLength > math.MaxInt32 {\n\t\treturn 0, fmt.Errorf(\"Total length of the prefix message is out of range: %d\", totalLength)\n\t}\n\tbuf := make([]byte, 0, totalLength)\n\tbuf = append(buf, w.prefix...)\n\tbuf = append(buf, p...)\n\n\treturn os.Stderr.Write(buf)\n}\n","sourceCodeStart":92,"sourceCodeEnd":118,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/testlog/testlog.go#L92-L118","documentation":"The test log writer prefixes each line with a tag before writing to stderr. Before building the buffer it checks that the combined length of prefix + message fits in a positive int32; if not it returns this error instead of allocating. It protects against overflow and absurdly large writes that would break test line detection.","triggerScenarios":"Writing (Write method on the test logger) a single log message p whose length plus len(w.prefix) exceeds math.MaxInt32 (or is negative, only via overflow) — i.e. attempting to write a >2GB log line through the test logger.","commonSituations":"Tests that accidentally log enormous payloads (e.g. dumping a multi-gigabyte request/response body, a huge byte slice, or an unbounded loop of data in one Print call) under test debugging.","solutions":["Find the test logging a >2GB single line and truncate or summarize the payload before logging.","Log only lengths/hashes of large data instead of the full contents.","Split large output into multiple smaller log lines."],"exampleFix":"// before\nt.Logf(\"payload: %s\", hugeBody) // >2GB single line\n// after\nt.Logf(\"payload: %d bytes (sha256 %x)\", len(hugeBody), sha256.Sum256(hugeBody))","handlingStrategy":"validation","validationCode":"func safeTestLog(w *testlog.TestWriter, prefix string, msg []byte) error {\n    if len(prefix)+len(msg) > math.MaxInt32 {\n        return fmt.Errorf(\"log payload too large: %d bytes\", len(msg))\n    }\n    _, err := w.Write(prefix, msg)\n    return err\n}","typeGuard":null,"tryCatchPattern":"if _, err := w.Write(prefix, data); err != nil && strings.Contains(err.Error(), \"out of range\") {\n    t.Logf(\"payload too large to log: %d bytes\", len(data))\n}","preventionTips":["Never log raw request/response bodies or huge byte slices in tests; log sizes and hashes.","Truncate log payloads to a sane maximum before writing.","Review tests that print looped or accumulated output in a single call."],"tags":["logging","testing","buffer-overflow"],"backgroundTag":"log-line-too-large","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}