{"record":{"id":"8ff057ccf537f0b7","repo":"gohugoio/hugo","slug":"integer-overflow-q","errorCode":null,"errorMessage":"integer overflow: %q","messagePattern":"integer overflow: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/internal/go_templates/texttemplate/parse/node.go","lineNumber":698,"sourceCode":"\t\tif i == 0 {\n\t\t\tn.IsUint = true // in case of -0.\n\t\t\tn.Uint64 = u\n\t\t}\n\t}\n\t// If an integer extraction succeeded, promote the float.\n\tif n.IsInt {\n\t\tn.IsFloat = true\n\t\tn.Float64 = float64(n.Int64)\n\t} else if n.IsUint {\n\t\tn.IsFloat = true\n\t\tn.Float64 = float64(n.Uint64)\n\t} else {\n\t\tf, err := strconv.ParseFloat(text, 64)\n\t\tif err == nil {\n\t\t\t// If we parsed it as a float but it looks like an integer,\n\t\t\t// it's a huge number too large to fit in an int. Reject it.\n\t\t\tif !strings.ContainsAny(text, \".eEpP\") {\n\t\t\t\treturn nil, fmt.Errorf(\"integer overflow: %q\", text)\n\t\t\t}\n\t\t\tn.IsFloat = true\n\t\t\tn.Float64 = f\n\t\t\t// If a floating-point extraction succeeded, extract the int if needed.\n\t\t\tif !n.IsInt && float64(int64(f)) == f {\n\t\t\t\tn.IsInt = true\n\t\t\t\tn.Int64 = int64(f)\n\t\t\t}\n\t\t\tif !n.IsUint && float64(uint64(f)) == f {\n\t\t\t\tn.IsUint = true\n\t\t\t\tn.Uint64 = uint64(f)\n\t\t\t}\n\t\t}\n\t}\n\tif !n.IsInt && !n.IsUint && !n.IsFloat {\n\t\treturn nil, fmt.Errorf(\"illegal number syntax: %q\", text)\n\t}\n\treturn n, nil","sourceCodeStart":680,"sourceCodeEnd":716,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/internal/go_templates/texttemplate/parse/node.go#L680-L716","documentation":"When a numeric literal in a template parses as a float but contains none of '.', 'e', 'E', 'p', 'P' (i.e. it looks like an integer), the parser treats it as an integer too large to fit in int64/uint64 and rejects it as an overflow. See node.go:692-699.","triggerScenarios":"A template literal like {{ 999999999999999999999 }} whose magnitude exceeds 64-bit integer range.","commonSituations":"Hardcoding huge IDs, timestamps, or hashes directly in templates; code-generated templates inserting oversized numeric tokens.","solutions":["Quote the value as a string and handle it as text in the template.","Express the number with scientific notation using an exponent character (e.g. 1e21) so it is treated as a float.","Compute or pass the value from Go as typed data instead of an inline literal."],"exampleFix":"// before\n{{ 999999999999999999999 }}\n\n// after\n{{ \"999999999999999999999\" }}","handlingStrategy":"validation","validationCode":"// Reject oversized integer literals before they reach the parser.\nfunc safeIntLiteral(s string) (any, error) {\n    if _, err := strconv.ParseInt(s, 0, 64); err == nil { return s, nil }\n    if _, err := strconv.ParseUint(s, 0, 64); err == nil { return s, nil }\n    if strings.ContainsAny(s, \".eEpP\") { return s, nil }\n    return nil, fmt.Errorf(\"integer too large; pass as string\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := template.New(\"t\").Parse(body); err != nil { return err }","preventionTips":["Pass very large numbers as quoted strings or as typed data.","Use scientific notation with an exponent character when float semantics are acceptable."],"tags":["template","go","parse","numeric","overflow"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}