diff --git a/topdown/parse_bytes.go b/topdown/parse_bytes.go index 9bea175e20..817edd5ee3 100644 --- a/topdown/parse_bytes.go +++ b/topdown/parse_bytes.go @@ -14,18 +14,16 @@ import ( "github.com/open-policy-agent/opa/topdown/builtins" ) -type multiplier int - const ( - none multiplier = 1 - kb = 1000 - ki = 1024 - mb = kb * 1000 - mi = ki * 1024 - gb = mb * 1000 - gi = mi * 1024 - tb = gb * 1000 - ti = gi * 1024 + none int64 = 1 + kb = 1000 + ki = 1024 + mb = kb * 1000 + mi = ki * 1024 + gb = mb * 1000 + gi = mi * 1024 + tb = gb * 1000 + ti = gi * 1024 ) // The rune values for 0..9 as well as the period symbol (for parsing floats) @@ -46,7 +44,7 @@ var ( ) func builtinNumBytes(a ast.Value) (ast.Value, error) { - var m multiplier + var m int64 raw, err := builtins.StringOperand(a, 1) if err != nil { @@ -88,14 +86,14 @@ func builtinNumBytes(a ast.Value) (ast.Value, error) { return nil, errUnitNotRecognized(unitStr) } - num, err := strconv.Atoi(numStr) + num, err := strconv.ParseInt(numStr, 10, 64) if err != nil { return nil, errIntConv } - total := num * int(m) + total := num * m - return builtins.IntToNumber(big.NewInt(int64(total))), nil + return builtins.IntToNumber(big.NewInt(total)), nil } // Makes the string lower case and removes spaces and quotation marks