mikefarah/yq · error
result of repeating string (%v bytes) by %v would exceed %v
Error message
result of repeating string (%v bytes) by %v would exceed %v bytes
What it means
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.
Source
Thrown at pkg/yqlib/operator_multiply.go:161
if lhs.Tag == "!!str" {
stringNode = lhs
intNode = rhs
} else {
stringNode = rhs
intNode = lhs
}
target := lhs.CopyWithoutContent()
target.UpdateAttributesFrom(stringNode, assignPreferences{})
count, err := parseInt(intNode.Value)
if err != nil {
return nil, err
} else if count < 0 {
return nil, fmt.Errorf("cannot repeat string by a negative number (%v)", count)
}
maxResultLen := 10 * 1024 * 1024 // 10 MiB
if count > 0 && len(stringNode.Value) > maxResultLen/count {
return nil, fmt.Errorf("result of repeating string (%v bytes) by %v would exceed %v bytes", len(stringNode.Value), count, maxResultLen)
}
target.Value = strings.Repeat(stringNode.Value, count)
return target, nil
}
func mergeObjects(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode, preferences multiplyPreferences) (*CandidateNode, error) {
var results = list.New()
// only need to recurse the array if we are doing a deep merge
prefs := recursiveDescentPreferences{RecurseArray: preferences.DeepMergeArrays,
TraversePreferences: traversePreferences{DontFollowAlias: true, IncludeMapKeys: true, ExactKeyMatch: true}}
log.Debugf("merge - preferences.DeepMergeArrays %v", preferences.DeepMergeArrays)
log.Debugf("merge - preferences.AppendArrays %v", preferences.AppendArrays)
err := recursiveDecent(results, context.SingleChildContext(rhs), prefs)
if err != nil {
return nil, err
}View on GitHub (pinned to 8b5af0694b)
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
Example fix
// before yq '"x" * .count' f.yml // count=10000000 -> would exceed 10485760 bytes // after yq '"x" * ([.count, 10000] | min)' f.yml
Defensive patterns
Strategy: validation
Validate before calling
yq 'select((.s | length) * .n <= 10000000) | .s * .n' f.yml
Try / catch
// shell if ! out=$(yq '.s * .n' f.yml 2>&1); then echo "repeat too large: $out"; fi
Prevention
- Cap multipliers: '[.n, 1000] | min'
- Remember the 10 MiB (10485760 bytes) product limit
- Generate very large outputs with dedicated tooling instead of yq
When it happens
Trigger: 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'.
Common situations: 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.
Related errors
- cannot repeat string by a negative number (%v)
- no support for input format
- aborted
- unrecognised type :( %v
- orderedMap: invalid yaml node
AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05).
Data as JSON: /api/errors/ee7775856c854c50.
Report an issue: GitHub.