8000 fix: refuse impossible water masses, huge integers and hidden characters in ratio inputs by rafatahmed · Pull Request #484 · rafatahmed/Flahax · GitHub
[go: up one dir, main page]

Skip to content

fix: refuse impossible water masses, huge integers and hidden characters in ratio inputs - #484

Merged
rafatahmed merged 1 commit into
mainfrom
fix/ratio-inputs-481
Dec 3, 2026
Merged

rafatahmed merged 1 commit into
mainfrom
fix/ratio-inputs-481

Conversation

@rafatahmed
@rafatahmed rafatahmed commented Dec 3, 2026 •
Copy link
Copy Markdown
Owner

Summary

Fixes the three bugs from the ratio command fuzzing audit (#437).

Closes #481
Closes #482
Closes #483

 SolventBasis                      (water files, workflow, and now ratio)
+  refuse water_mass_kg / final_volume_litres > 2 kg
-  the same check only inside water_input.water_basis

 inputs
+  finite(value): math.isfinite, False for an integer too large for a float
 54 modules
-  math.isfinite on caller numbers
+  finite

 ratio
+  text_without_controls(product name), text_without_controls(water analysis_id)
 composition
+  an unknown nutrient key is shown escaped

The diff is wide because the integer fix replaces every inline finiteness check outside the solver modules. A new test fails if math.isfinite appears again outside that listed set.

Evidence

Input Before After
ratio, real water, 10 L, water_mass_kg 10000 saturation check passed refused: declares 1000 kg of water per litre
workflow equilibrium, 100 L, water_mass_kg 100000 chemistry calculated chemistry stage blocked, out_of_range
ratio, water_mass_kg 1 followed by 400 zeros traceback in many fields water_mass_kg must be finite
batch --products, such an integer as an ion count traceback chemistry stage blocked: K+ count must be a positive number
ratio product name with an escape code raw bytes on the terminal product name has a control character
  • tests/test_ratio_input_limits.py failed before the fix (699 OverflowError subtests among them) and passes after. It puts the integer into every numeric field of every ratio example, except inside stock_evidence and batch_stability, whose handlers already name the error.
  • 121 local test modules (those touching the changed inputs, plus the documentation tests) passed in batches before the last small edit; the 8000 reference-fixture, input-limit and documentation modules were rerun after it. The full suite and the coverage gate are left to CI.
  • No conversion, speciation, saturation or EC calculation changed, so the PHREEQC golden fixture is not re-captured.

Remaining limit

  • Water mass mistakes up to 2 kg per litre are still accepted. On the real-water example at exactly 2, brushite already changes from precipitating to not (SI 0.37 to -0.09); the recipe as a whole still fails on the other two phosphates.
  • Free text in product provenance and grade records is still accepted. It appears only in JSON output, where it stays escaped.

Checked against earlier work

Merge Danger

Door: two-way

Blast Radius: inputs

SolventBasis is public: a caller constructing more than 2 kg of water per litre now gets DeliveryError. For every other value, finite answers exactly as math.isfinite did.

…ers in ratio inputs

- ratio and every SolventBasis refuse more than 2 kg of water per litre (#481)
- caller-number checks use inputs.finite, so an integer too large for a float
  is refused by name instead of raising OverflowError (#482)
- ratio product names and water analysis_id refuse control characters, and an
  unknown nutrient key is shown escaped (#483)
@rafatahmed rafatahmed added the bug Something isn't working label Dec 3, 2026
@rafatahmed rafatahmed self-assigned this Dec 3, 2026
@read-the-docs-community
Copy link
Copy Markdown

📖 4 files modified


Preview · build overview · Flahax · built Dec. 3, 2026, 5:09 p.m. UTC

@codecov
8000 codecov Bot commented Dec 3, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d823cce) to head (88393ff).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #484   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          155       155           
  Lines        18362     18380   +18     
  Branches      3713      3714    +1     
=========================================
+ Hits         18362     18380   +18     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rafatahmed
rafatahmed marked this pull request as ready for review December 3, 2026 17:44
@rafatahmed
rafatahmed merged commit 3334014 into main Dec 3, 2026
28 checks passed
@rafatahmed
rafatahmed deleted the fix/ratio-inputs-481 branch December 3, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

1 participant

0