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
+6
View File
@@ -54,6 +54,12 @@ func oaiImage2AliImageRequest(info *relaycommon.RelayInfo, request dto.ImageRequ
}
}
// Parameters may come from Extra["parameters"], bypassing the standard
// top-level n validation; enforce the same bound before it becomes a
// billing multiplier.
if imageRequest.Parameters.N < 0 || imageRequest.Parameters.N > dto.MaxImageN {
return nil, fmt.Errorf("parameters.n must be an integer between 1 and %d", dto.MaxImageN)
}
if imageRequest.Parameters.N != 0 {
info.PriceData.AddOtherRatio("n", float64(imageRequest.Parameters.N))
}