Repository navigation
fix(capture-core): reject duplicate JSON keys and non-finite numbers in load_state/sha_mapping and check seal.alg in check_seal (#366) - #370
Conversation
|
🟡 Contributor Check: MEDIUM
Automated check by AgenTrust Contributor Check. |
carloshvp
left a comment
There was a problem hiding this comment.
Reviewed exact head e8ff9802582d6738ac8e713c58ff0f5581ca928d in an isolated checkout.
The capture-core changes reject non-finite values before hashing, refuse duplicate/non-finite persisted JSON, and check a present seal algorithm while retaining the established legacy behavior when that field is absent. Existing valid seal/state controls and the new malformed-input cases pass. No blocking finding in the changed package.
Validation: all 56 package tests passed, scoped Ruff and diff whitespace checks passed, and all PR commits carry sign-offs. This approval does not establish completion of hosted CI or the maintainer policy gate.
Reviewed with OpenAI Codex.
|
Hosted CI follow-up at head The current actions/python-versions manifest publishes Python 3.9.25 x64 builds for Ubuntu 22.04 and 24.04, so pinning this compatibility job to ubuntu-24.04 is a concrete way to retain the declared 3.9 coverage: https://github.com/actions/python-versions/blob/9834b4e4911ca2950ff6c3b7547f09eacc006848/versions-manifest.json. This runner setup failure is separate from the package source review and its 56 locally passing tests. |
There was a problem hiding this comment.
the overall changes looks good, but still some places need hardening:
- load_state still accepts exponent overflow, 1e309, -1e309, 1e999 etc. are parsed as inf/-inf instead of being rejected. parse_constant only catches literal NaN/Infinity. Need a validating parse_float with math.isfinite.
- check_seal can now raise, because of allow_nan=False in sha_mapping, a snapshot containing nan/inf makes check_seal raise ValueError. This breaks the documented “Never raises” contract. It should return INTEGRITY_BROKEN instead. Especially bad when combined with (1): load_state accepts 1e309 -> later check_seal raises.
- save_state still writes non-finite JSON, It uses the default allow_nan=True, so it can write files that load_state immediately rejects. Prefer allow_nan=False here too.
Current test covers duplicate key + literal NaN + wrong alg, but misses:
- 1e309 / -1e309
- nested overflow
- check_seal with in-memory nan/inf (must not raise, must return BROKEN)
- save_state with non-finite values
also rebase branch on main
dinakarjs
left a comment
There was a problem hiding this comment.
Source follow-up at e8ff980, supporting the distinct entry-point checks in Rajnish's latest review. The diff adds parse_constant rejection and allow_nan=False for hashing, but those changes need to preserve the public load/save/check contracts together.
Please use separate regression cases for exponent overflow (including nested values), direct in-memory non-finite input to check_seal, and attempted non-finite save_state output. Preserve the expected outcomes separately: corrupt loads return None; seal verification returns INTEGRITY_BROKEN without raising; a refused save should leave an existing valid destination intact. Retain a finite save/load/seal positive control.
The combined added test can stop at its first failure, so independently collected cases would make each boundary observable. This is source inspection and follow-up to the existing review, not a fresh execution or an additional independently reproduced defect. Reviewed with OpenAI Codex.
…in load_state/save_state/sha_mapping and preserve check_seal contract (agentrust-io#366) - Reject duplicate JSON object keys, NaN/Infinity constants, and float exponent overflow (parse_float with math.isfinite) in load_state, returning None. - Pass allow_nan=False in save_state and sha_mapping so non-finite floats are refused before writing or hashing. - Catch (ValueError, TypeError) around state_digest in check_seal and verify seal.get("alg") == "SHA-256" when "alg" is present so in-memory non-finite snapshots return INTEGRITY_BROKEN without raising. Closes agentrust-io#366 Signed-off-by: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com>
e8ff980 to
4e9cec9
Compare
|
@rajnisht7 @dinakarjs @carloshvp Rebased onto
|
dinakarjs
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 4e9cec9 on Linux/Python 3.12.14.
The load/save/seal contracts now agree: corrupt and exponent-overflow loads return None, direct non-finite snapshots return INTEGRITY_BROKEN, and refused non-finite saves preserve an existing destination. Separate regressions and a finite round-trip control are present. Fresh hash-locked capture-core environment: 76 tests pass; syntax/error lint selection and whitespace pass. The earlier contract/coverage follow-up is addressed. This review covers the capture-core software change; unrelated example integrations and hosted merge gates remain separate.
Reviewed with OpenAI Codex.
carloshvp
left a comment
There was a problem hiding this comment.
Reviewed current head 4e9cec9d658692626973550f5825fd208a7c89a1 in an isolated checkout.
The persisted-state parser rejects duplicate members, literal non-finite constants and exponent overflow; saving non-finite in-memory data preserves the prior valid file. Seal checking returns a broken verdict rather than leaking a numeric-serialization error, and a present unsupported seal algorithm is refused. All 76 package tests and 60 root tests pass.
The repository CI Ruff selection and whitespace checks pass; all PR commits carry DCO sign-offs. This approves the bounded software scope. Current-head hosted checks and maintainer requirements remain applicable.
Reviewed with OpenAI Codex.
Summary
NaN/Infinityconstants inagentrust_capture_core.state.load_state(returningNone) and passallow_nan=Falseinagentrust_capture_core.hashing.sha_mapping.seal.get("alg") == "SHA-256"when"alg"is present inagentrust_capture_core.seal.check_seal(returningINTEGRITY_BROKENon algorithm mismatch).Closes #366
Validation
python -m pytest packages/agentrust-capture-core/tests/test_core.py -q