fix(billing): validate quantity parameters and harden quota calculations
Bound user-supplied count/duration parameters at request validation, route ratio multipliers through guarded setters, and use saturating int conversions in all quota math paths.
This commit is contained in:
+7
-2
@@ -1,6 +1,9 @@
|
||||
package types
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
type GroupRatioInfo struct {
|
||||
GroupRatio float64
|
||||
@@ -31,7 +34,9 @@ func (p *PriceData) AddOtherRatio(key string, ratio float64) {
|
||||
if p.OtherRatios == nil {
|
||||
p.OtherRatios = make(map[string]float64)
|
||||
}
|
||||
if ratio <= 0 {
|
||||
// NaN/Inf would poison every downstream quota multiplication
|
||||
// (int(NaN * quota) wraps to a negative charge).
|
||||
if !(ratio > 0) || math.IsInf(ratio, 1) {
|
||||
return
|
||||
}
|
||||
p.OtherRatios[key] = ratio
|
||||
|
||||
Reference in New Issue
Block a user