T09 · Insecure Skill Coding Practices
- Location
scripts/solver.py:343- Finding
Zero computed prices cause unhandled division-by-zero failures in the Python solver
- Content
View full analysis
- Remediation
View remediation
float: if not math.isfinite(value) or value <= 0: raise ValueError(f"{name} must be a finite positive number") return value ``` 2. Validate every computed price at the solver boundary: ```python actual_price = round(base_price * multiplier) if actual_price <= 0: raise ValueError( f"Computed price for {name!r} must be greater than zero" ) ``` 3. Validate loaded base-price data. Require positive integers and reject booleans, floats, negative values, and zero. 4. Add defensive checks before all modulo and division operations: ```python if low_group.actual_price <= 0: continue ``` 5. Apply reasonable upper and lower bounds to targets and multipliers. 6. Catch validation errors in the command handler and return a controlled error message instead of a traceback. 7. Add regression tests for zero, negative, very small, `NaN`, and infinite multipliers. ]]>
