Skip to content

Commit 342efb2

Browse files
committed
Fixed panic on multipling string by very large number #2211
1 parent 2201381 commit 342efb2

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/yqlib/operator_multiply.go

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ func repeatString(lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error
155155
return nil, err
156156
} else if count < 0 {
157157
return nil, fmt.Errorf("Cannot repeat string by a negative number (%v)", count)
158+
} else if count > 10000000 {
159+
return nil, fmt.Errorf("Cannot repeat string by more than 100 million (%v)", count)
158160
}
159161
target.Value = strings.Repeat(stringNode.Value, count)
160162

pkg/yqlib/operator_multiply_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ var multiplyOperatorScenarios = []expressionScenario{
208208
expression: `"banana" * .n`,
209209
expectedError: "Cannot repeat string by a negative number (-4)",
210210
},
211+
{
212+
description: "Multiply string X by more than 100 million",
213+
// very large string.repeats causes a panic
214+
skipDoc: true,
215+
document: `n: 100000001`,
216+
expression: `"banana" * .n`,
217+
expectedError: "Cannot repeat string by more than 100 million (100000001)",
218+
},
211219
{
212220
description: "Multiply int node X string",
213221
document: `n: 4

0 commit comments

Comments
 (0)