mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Fixed panic on multipling string by very large number #2211
This commit is contained in:
parent
2201381235
commit
342efb23ff
@ -155,6 +155,8 @@ func repeatString(lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error
|
|||||||
return nil, err
|
return nil, err
|
||||||
} else if count < 0 {
|
} else if count < 0 {
|
||||||
return nil, fmt.Errorf("Cannot repeat string by a negative number (%v)", count)
|
return nil, fmt.Errorf("Cannot repeat string by a negative number (%v)", count)
|
||||||
|
} else if count > 10000000 {
|
||||||
|
return nil, fmt.Errorf("Cannot repeat string by more than 100 million (%v)", count)
|
||||||
}
|
}
|
||||||
target.Value = strings.Repeat(stringNode.Value, count)
|
target.Value = strings.Repeat(stringNode.Value, count)
|
||||||
|
|
||||||
|
@ -208,6 +208,14 @@ var multiplyOperatorScenarios = []expressionScenario{
|
|||||||
expression: `"banana" * .n`,
|
expression: `"banana" * .n`,
|
||||||
expectedError: "Cannot repeat string by a negative number (-4)",
|
expectedError: "Cannot repeat string by a negative number (-4)",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Multiply string X by more than 100 million",
|
||||||
|
// very large string.repeats causes a panic
|
||||||
|
skipDoc: true,
|
||||||
|
document: `n: 100000001`,
|
||||||
|
expression: `"banana" * .n`,
|
||||||
|
expectedError: "Cannot repeat string by more than 100 million (100000001)",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Multiply int node X string",
|
description: "Multiply int node X string",
|
||||||
document: `n: 4
|
document: `n: 4
|
||||||
|
Loading…
Reference in New Issue
Block a user