{"record":{"id":"601376bf42dd20af","repo":"JuliusBrussee/caveman","slug":"json-number-exponent-exceeds-supported-range","errorCode":null,"errorMessage":"JSON number exponent exceeds supported range","messagePattern":"JSON number exponent exceeds supported range","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/proposalrun/proposalrun.go","lineNumber":289,"sourceCode":"\tif len(raw) == 0 {\n\t\treturn 0, fmt.Errorf(\"invalid JSON number exponent\")\n\t}\n\tnegative := false\n\tif raw[0] == '+' || raw[0] == '-' {\n\t\tnegative = raw[0] == '-'\n\t\traw = raw[1:]\n\t}\n\tif len(raw) == 0 {\n\t\treturn 0, fmt.Errorf(\"invalid JSON number exponent\")\n\t}\n\tvalue := 0\n\tfor i := 0; i < len(raw); i++ {\n\t\tif raw[i] < '0' || raw[i] > '9' {\n\t\t\treturn 0, fmt.Errorf(\"invalid JSON number exponent\")\n\t\t}\n\t\tdigit := int(raw[i] - '0')\n\t\tif value > (maxJSONBNumberExponent-digit)/10 {\n\t\t\treturn 0, fmt.Errorf(\"JSON number exponent exceeds supported range\")\n\t\t}\n\t\tvalue = value*10 + digit\n\t}\n\tif negative {\n\t\treturn -value, nil\n\t}\n\treturn value, nil\n}\n\n// formatTime pins the created_at representation: UTC, microsecond resolution\n// (Postgres TIMESTAMPTZ stores microseconds, so truncating here makes the value\n// hashed at write time equal the value read back at verify time), RFC3339Nano.\nfunc formatTime(t time.Time) string {\n\treturn t.UTC().Truncate(time.Microsecond).Format(time.RFC3339Nano)\n}\n\n// RowHash computes the pinned canonical row hash:\n//","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/proposalrun/proposalrun.go#L271-L307","documentation":"parseJSONExponent throws when the exponent's absolute value exceeds maxJSONBNumberExponent while parsing digit by digit with overflow protection. PostgreSQL numeric supports exponents only within a bounded range; exponents beyond it (e.g. 1e999999999) cannot be represented, so the library rejects the literal before reaching the database.","triggerScenarios":"canonicalizeJSONNumber -> normalizeJSONNumber on a literal with an enormous exponent such as 1e1000000 or 5e-999999999, where |exponent| > maxJSONBNumberExponent.","commonSituations":"Scientific-computation output (astronomically large/small values), bignum libraries serializing to scientific notation with unbounded exponents, adversarial or fuzzed JSON payloads.","solutions":["Clamp or quantize the value into the supported exponent range before inserting.","Represent out-of-range values as strings or as separate mantissa/exponent fields in detail.","Cap exponents at the producer side (format with limited precision/exponent).","Reject such payloads at the API boundary with a clear client-facing message."],"exampleFix":"// before\ndetail := []byte(`{\"v\": 1e1000000}`)\n// after\ndetail := []byte(`{\"v\": \"1e1000000\"}`) // or clamp to 0 / MaxFloat64 semantics","handlingStrategy":"validation","validationCode":"func exponentInRange(lit string) bool {\n\ti := strings.IndexAny(lit, \"eE\")\n\tif i < 0 { return true }\n\te, err := strconv.Atoi(lit[i+1:])\n\treturn err == nil && e <= maxJSONBNumberExponent && e >= -maxJSONBNumberExponent\n}","typeGuard":null,"tryCatchPattern":"if !exponentInRange(lit) {\n\t// clamp value or serialize as string field\n\treturn nil\n}","preventionTips":["Clamp scientific-computation output to the supported exponent range","Serialize extreme values as strings in detail JSON","Fuzz-test ingestion with huge-exponent literals"],"tags":["json","numeric-precision","postgresql","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}