From 9a253f1b9e82545f9d5873d19f61a2314770c0aa Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Wed, 22 Apr 2026 18:37:45 -0700 Subject: [PATCH] Fix repeatString overflow test on 32-bit platforms The test literal "ab" * 4611686018427387904 (2^62) exceeds MaxInt32, so parseInt rejects it before the size guard runs. Compute the count with 1 << (bits.UintSize - 2) to yield 2^30 on 32-bit and 2^62 on 64-bit. Both values, when doubled by len("ab"), wrap past MaxInt and bypass a naive len*count guard, exercising the division-safe check added in #2644. Signed-off-by: Jan Dubois Co-Authored-By: Claude Opus 4.6 (1M context) --- pkg/yqlib/operator_multiply_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/yqlib/operator_multiply_test.go b/pkg/yqlib/operator_multiply_test.go index 2c31b6f9..66256c92 100644 --- a/pkg/yqlib/operator_multiply_test.go +++ b/pkg/yqlib/operator_multiply_test.go @@ -2,6 +2,7 @@ package yqlib import ( "fmt" + "math/bits" "strings" "testing" ) @@ -707,11 +708,13 @@ var multiplyOperatorScenarios = []expressionScenario{ expectedError: "result of repeating string (1 bytes) by 99999999 would exceed 10485760 bytes", }, { - // The size guard must not overflow: len * count can wrap to - // a negative or small value on 64-bit, bypassing the check. + // Pick a count whose product with len("ab") overflows int on + // any architecture: 2^30 on 32-bit, 2^62 on 64-bit. Doubling + // either yields MaxInt+1, which wraps to MinInt and bypasses + // a naive len*count guard. skipDoc: true, - expression: `"ab" * 4611686018427387904`, - expectedError: "result of repeating string (2 bytes) by 4611686018427387904 would exceed 10485760 bytes", + expression: fmt.Sprintf(`"ab" * %d`, 1<<(bits.UintSize-2)), + expectedError: fmt.Sprintf("result of repeating string (2 bytes) by %d would exceed 10485760 bytes", 1<<(bits.UintSize-2)), }, }