{"record":{"id":"3904cdcf00d4f299","repo":"gohugoio/hugo","slug":"size-of-result-exceeds-limit","errorCode":null,"errorMessage":"size of result exceeds limit","messagePattern":"size of result exceeds limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/collections.go","lineNumber":417,"sourceCode":"\tcase reflect.Slice:\n\tdefault:\n\t\treturn nil, errors.New(\"argument must be a slice\")\n\t}\n\n\tsliceCopy := reflect.MakeSlice(v.Type(), v.Len(), v.Len())\n\n\tfor i := v.Len() - 1; i >= 0; i-- {\n\t\telement := sliceCopy.Index(i)\n\t\telement.Set(v.Index(v.Len() - 1 - i))\n\t}\n\n\treturn sliceCopy.Interface(), nil\n}\n\n// Sanity check for slices created by Seq and D.\nconst maxSeqSize = 1000000\n\nvar errSeqSizeExceedsLimit = errors.New(\"size of result exceeds limit\")\n\n// Seq creates a sequence of integers from args. It's named and used as GNU's seq.\n//\n// Examples:\n//\n//\t3 => 1, 2, 3\n//\t1 2 4 => 1, 3\n//\t-3 => -1, -2, -3\n//\t1 4 => 1, 2, 3, 4\n//\t1 -2 => 1, 0, -1, -2\nfunc (ns *Namespace) Seq(args ...any) ([]int, error) {\n\tif len(args) < 1 || len(args) > 3 {\n\t\treturn nil, errors.New(\"invalid number of arguments to Seq\")\n\t}\n\n\tintArgs := cast.ToIntSlice(args)\n\tif len(intArgs) < 1 || len(intArgs) > 3 {\n\t\treturn nil, errors.New(\"invalid arguments to Seq\")","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/collections/collections.go#L399-L435","documentation":"Thrown by the Seq function (and D) via the shared errSeqSizeExceedsLimit sentinel (line 417) when the requested sequence would exceed maxSeqSize (1,000,000). Trips on two conditions: when 'last' < -1,000,000, or when the computed size ((last-first)/inc + 1) is <=0 or > 1,000,000. This is a resource guard against unbounded slice allocation.","triggerScenarios":"Calling {{ seq 1 1 9999999 }} (increment 1, end ~10M -> size ~10M > 1M); {{ seq 1 0 5000000 }}; passing front matter-derived large bounds; a negative increment producing an oversized backward range. Also when the size computation overflows logically to <=0.","commonSituations":"Looping over large data sets with seq in a template; computed bounds from pagination/counts going unexpectedly large; accidentally passing a byte count or ID as a seq end.","solutions":["Reduce the range: cap 'last' so (last-first)/inc+1 stays under 1,000,000.","Switch to a Go-backed shortcode or partial that streams the range instead of materializing it in the template.","Sanitize inputs: clamp the end value with math.Min before passing to seq."],"exampleFix":"// before\n{{ seq 1 1 9999999 }}\n// after\n{{ $end := math.Min 999999 $computedEnd }}\n{{ seq 1 1 $end }}","handlingStrategy":"validation","validationCode":"{{ $end := math.Min 999999 $computedEnd }}\n{{ seq 1 1 $end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cap the 'last' value so (last-first)/inc+1 stays under 1,000,000.","Avoid materializing huge ranges in templates; use a Go-backed shortcode.","Sanitize large computed bounds with math.Min before passing to seq."],"tags":["hugo","template","collections","seq","resource-limit","validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}