{"record":{"id":"ee7775856c854c50","repo":"mikefarah/yq","slug":"result-of-repeating-string-v-bytes-by-v-would","errorCode":null,"errorMessage":"result of repeating string (%v bytes) by %v would exceed %v bytes","messagePattern":"result of repeating string \\((.+?) bytes\\) by (.+?) would exceed (.+?) bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_multiply.go","lineNumber":161,"sourceCode":"\tif lhs.Tag == \"!!str\" {\n\t\tstringNode = lhs\n\t\tintNode = rhs\n\t} else {\n\t\tstringNode = rhs\n\t\tintNode = lhs\n\t}\n\ttarget := lhs.CopyWithoutContent()\n\ttarget.UpdateAttributesFrom(stringNode, assignPreferences{})\n\n\tcount, err := parseInt(intNode.Value)\n\tif err != nil {\n\t\treturn nil, err\n\t} else if count < 0 {\n\t\treturn nil, fmt.Errorf(\"cannot repeat string by a negative number (%v)\", count)\n\t}\n\tmaxResultLen := 10 * 1024 * 1024 // 10 MiB\n\tif count > 0 && len(stringNode.Value) > maxResultLen/count {\n\t\treturn nil, fmt.Errorf(\"result of repeating string (%v bytes) by %v would exceed %v bytes\", len(stringNode.Value), count, maxResultLen)\n\t}\n\ttarget.Value = strings.Repeat(stringNode.Value, count)\n\n\treturn target, nil\n}\n\nfunc mergeObjects(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode, preferences multiplyPreferences) (*CandidateNode, error) {\n\tvar results = list.New()\n\n\t// only need to recurse the array if we are doing a deep merge\n\tprefs := recursiveDescentPreferences{RecurseArray: preferences.DeepMergeArrays,\n\t\tTraversePreferences: traversePreferences{DontFollowAlias: true, IncludeMapKeys: true, ExactKeyMatch: true}}\n\tlog.Debugf(\"merge - preferences.DeepMergeArrays %v\", preferences.DeepMergeArrays)\n\tlog.Debugf(\"merge - preferences.AppendArrays %v\", preferences.AppendArrays)\n\terr := recursiveDecent(results, context.SingleChildContext(rhs), prefs)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_multiply.go#L143-L179","documentation":"To avoid exhausting memory, yq caps string repetition at 10 MiB (maxResultLen). Before calling strings.Repeat, it checks len(string)*count and throws this error when the resulting size would exceed the cap. The error reports the string byte length, the count, and the 10485760-byte limit.","triggerScenarios":"Expressions like '\"pad\" * 99999999' or repeating a large string (e.g. several KB) by a large factor so that len*count > 10485760, e.g. '\"xxxxxxxxxx\" (10KB) * 2000'.","commonSituations":"Generating padding/placeholder data, producing large test fixtures or payloads, template generation scripts where the multiplier comes from config or input data that grew unexpectedly.","solutions":["Reduce the repeat count or the source string size so the product stays under 10 MiB","Build the large output outside yq (e.g. with a shell loop, head -c, or a script) if you genuinely need >10MiB output","Validate the multiplier from input data before the multiply, e.g. select or assert the count is within an expected range"],"exampleFix":"// before\nyq '\"x\" * .count' f.yml      // count=10000000 -> would exceed 10485760 bytes\n// after\nyq '\"x\" * ([.count, 10000] | min)' f.yml","handlingStrategy":"validation","validationCode":"yq 'select((.s | length) * .n <= 10000000) | .s * .n' f.yml","typeGuard":null,"tryCatchPattern":"// shell\nif ! out=$(yq '.s * .n' f.yml 2>&1); then echo \"repeat too large: $out\"; fi","preventionTips":["Cap multipliers: '[.n, 1000] | min'","Remember the 10 MiB (10485760 bytes) product limit","Generate very large outputs with dedicated tooling instead of yq"],"tags":["yq","string-repetition","memory-limit","resource-limit"],"backgroundTag":"result-size-limit-exceeded","analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}