Skip to content

Holes first: fail closed under serde_json arbitrary_precision; no CLI panic on unwritable stderr - #50

Draft
hyperpolymath wants to merge 1 commit into
mainfrom
claude/beta-holes-first
Draft

hyperpolymath wants to merge 1 commit into
mainfrom
claude/beta-holes-first

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Holes-first deliverable for the beta track. Two defects found by reading the code against verification/PROOF-STATUS.adoc, each with a must-fail test and a fix. No proof is claimed here; the evidence is TESTED.

Hole 1: wrong canonical output and accepted non-I-JSON under Cargo feature unification

If any crate in a consumer's dependency graph enables serde_json/arbitrary_precision, Cargo turns it on for this crate too. serde_json then passes non-integer and out-of-range numbers to a generic Visitor as a one-member object keyed $serde_json::private::Number. Observed on main (67b89d9) in a scratch crate with that feature:

Input Reader Result on main
[1.5] parse_json Strict/Canonical, parse_jcs, canonicalize_bytes [{"$serde_json::private::Number":"1.5"}]
1e400 same accepted, emitted as an object
-0, 1.0, 1e-400 same emitted as an object

A generic visitor cannot tell that marker from a real object with the same key, so the strict readers now probe once and refuse to parse in such a build (require_binary64_number_model in src/strict.rs). to_jcs on a caller-built Value and JsonMode::Loose are unchanged; I probed them with the feature on and saw no wrong output, but that is a handful of probes, not a claim.

Hole 2: CLI panic (exit 101) when stderr is unwritable

eprintln! panics if stderr cannot be written. ijson-jcs canon 2>/dev/full on invalid input, and any usage error, exited 101 instead of the documented 2. Diagnostics are now best-effort writes; the exit status carries the verdict.

Evidence

Toolchain: rustc/cargo 1.99.1 (pinned in rust-toolchain.toml), Linux x86_64. cargo-llvm-cov 0.9.2.

Command Before fix After fix
cargo test --locked --test feature_unification --features serde_json/arbitrary_precision 0 passed, 3 failed 3 passed
cargo test --locked --test feature_unification not run before the fix 3 passed
cargo test --locked --test cli stderr_write failed, left: Some(101) right: Some(2) passed
cargo test --locked --all-features all suites passed, 0 failed
cargo clippy --locked --all-targets --all-features -- -D warnings clean
cargo fmt --all -- --check clean

Not run: the MSRV (1.85.0) job, macOS and Windows. CI covers them. The stderr test is Linux-only (/dev/full).

CI gains one step, "Feature-unification control", which runs the new test with the feature forced on, so the fail-closed branch is executed on every pull request.

Coverage gate: already red on main, not fixed here

scripts/proven-coverage.sh exits 1 on unmodified main: parse_jcs (src/lib.rs 204-209), the two BINARY64 visitor branches and from_str_binary64 are not reached by the counted suites, and two src/strict.rs exclusions were stale. No workflow in this repository runs that gate. This PR re-binds the exclusions for the lines it moved, adds one environment exclusion for the fail-closed branch, and drops the Visitor::expecting entry (no longer instrumented). The remaining 15 uncovered lines are all the pre-existing parse_jcs path and need counted tests, which belong to the test-needs thread.

Row census

Denominator: the 7 obligation rows of the parse_jcs plan table in PROOF-STATUS.adoc. This PR changes the status of 0 of 7. It adds evidence under "No panic on any input" (CLI path only) and exposes an assumption not yet in the ledger: serde_json's number model depends on features this crate does not control. The ledger edit comes with the proof PRs.

For the owner to rule

Recommended and implemented: fail closed (most correct; no silent change of meaning). Alternatives: (a) reject the marker key inside visit_map with no global probe, which is simpler to verify but refuses a legitimate object key in normal builds; (b) support arbitrary_precision by parsing numbers from the marker string, which widens the trusted surface. This class of defect (a generic serde visitor over serde_json::Deserializer) may exist in other estate crates and is worth a sweep beyond this repository.


Generated by Claude Code

…ble stderr

Two holes found reading the code against verification/PROOF-STATUS.adoc.

1. Cargo feature unification. When another crate in the graph enables
   serde_json/arbitrary_precision, serde_json hands non-integer and
   out-of-range numbers to a generic visitor as a one-member object keyed
   $serde_json::private::Number. The strict readers then canonicalised
   [1.5] to [{"$serde_json::private::Number":"1.5"}] and accepted 1e400.
   The strict readers now probe once and refuse to parse in that build.
   tests/feature_unification.rs holds in both configurations and CI runs
   it with the feature forced on.

2. The CLI used eprintln!, which panics when stderr cannot be written,
   so a refusal exited 101 instead of the documented 2. Diagnostics are
   now best-effort writes.

Coverage exclusions are re-bound to the moved lines; the entry for
Visitor::expecting is dropped because the line is no longer instrumented.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDfneftEg71bUadt3v3
@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 8d4a8272-88f9-4739-bd66-ac6c5a1a73b8
Commits

Reviewing files that changed from the base of the PR and between 67b89d9 and 4a6e090.

Files ignored due to path filters: 1

  • .proven/coverage-exclusions.tsv is excluded by !**/*.tsv
Files selected for processing: 5

  • .github/workflows/ci.yml
  • src/bin/ijson-jcs.rs
  • src/strict.rs
  • tests/cli.rs
  • tests/feature_unification.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sonarqubecloud

sonarqubecloud Bot commented Dec 1, 2026

Copy link
Copy Markdown

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

@gitnotebooks

gitnotebooks Bot commented Dec 1, 2026

Copy link
Copy Markdown

Review these changes at https://app.gitnotebooks.com/hyperpolymath/ijson-jcs/pull/50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants