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:
CaIon
2026-07-07 00:21:06 +08:00
parent 45f0484dc1
commit d0bd8aac74
17 changed files with 293 additions and 19 deletions
+7 -2
View File
@@ -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