StrictJson: valid numbers outside int64/double are rejected and decimal lexemes lose exactness #60

Closed
opened 2026-12-05 00:14:31 +00:00 by faumaray · 2 comments
Owner

Summary

Void::Data::StrictJson cannot represent JSON numbers outside int64/double range, and decimal numbers are stored only as double. Grammar-valid JSON is then rejected, and the integer/fraction distinction is lost.

Tested revision: main e6745ac8cbd0ed5dc8c8d8c254d99cbb20321e39 (2026-12-05), include/Void/Data/StrictJson.hpp (parseNumber).

Defect 1: valid numbers outside machine range are parse errors

  • {"n":9223372036854775808} (2^63) -> fail("integer is out of range")
  • {"n":1e-400} -> std::from_chars underflow -> fail("number is out of range")

Both are grammar-valid JSON numbers per RFC 8259. A consumer should receive a value (or a non-fatal "out of range" marker), not a document parse failure. Downstream, a JSON-RPC server must be able to answer -32600 Invalid Request rather than -32700 Parse error for an out-of-range id, and must still accept such numbers in unrelated parameters.

Defect 2: decimal lexemes lose exactness

1.0000000000000001 parses to double{1.0}, indistinguishable from 1. A JSON-RPC layer that promotes integral doubles to integer ids accepts the fractional id 1.0000000000000001 as id 1, so a rounded fractional id can change server lifecycle (e.g. trigger shutdown).

Expected

  • Preserve the raw number lexeme (or an exact decimal representation) so integral vs fractional and out-of-range can be decided exactly.
  • Accept out-of-range numbers without failing the document parse; expose their range state to consumers.
  • Keep allowDecimals for consumers that reject decimals.

Downstream evidence

VoidLanguageServer's vls_json_capabilities suite fails exactly these two cases against this revision:

  • rounded_fractional_id_cannot_change_lifecycle
  • valid_number_outside_machine_range_is_still_json
## Summary `Void::Data::StrictJson` cannot represent JSON numbers outside `int64`/`double` range, and decimal numbers are stored only as `double`. Grammar-valid JSON is then rejected, and the integer/fraction distinction is lost. Tested revision: main `e6745ac8cbd0ed5dc8c8d8c254d99cbb20321e39` (2026-12-05), `include/Void/Data/StrictJson.hpp` (`parseNumber`). ## Defect 1: valid numbers outside machine range are parse errors - `{"n":9223372036854775808}` (2^63) -> `fail("integer is out of range")` - `{"n":1e-400}` -> `std::from_chars` underflow -> `fail("number is out of range")` Both are grammar-valid JSON numbers per RFC 8259. A consumer should receive a value (or a non-fatal "out of range" marker), not a document parse failure. Downstream, a JSON-RPC server must be able to answer `-32600 Invalid Request` rather than `-32700 Parse error` for an out-of-range `id`, and must still accept such numbers in unrelated parameters. ## Defect 2: decimal lexemes lose exactness `1.0000000000000001` parses to `double{1.0}`, indistinguishable from `1`. A JSON-RPC layer that promotes integral doubles to integer ids accepts the fractional id `1.0000000000000001` as id `1`, so a rounded fractional id can change server lifecycle (e.g. trigger shutdown). ## Expected - Preserve the raw number lexeme (or an exact decimal representation) so integral vs fractional and out-of-range can be decided exactly. - Accept out-of-range numbers without failing the document parse; expose their range state to consumers. - Keep `allowDecimals` for consumers that reject decimals. ## Downstream evidence VoidLanguageServer's `vls_json_capabilities` suite fails exactly these two cases against this revision: - `rounded_fractional_id_cannot_change_lifecycle` - `valid_number_outside_machine_range_is_still_json`
Author
Owner

Fixed in 9cb86f8 on main.

  • New Void::Json::Strict::Number variant alternative preserves the exact lexeme plus exact isInteger, fitsInt64/int64Value, Range (in_range/overflow/underflow) and the nearest approximate double.
  • Grammar-valid numbers outside int64/double range now parse instead of failing: 9223372036854775808, -9223372036854775809, 1e309, -1e309, 1e-400.
  • Decimal lexemes that are not the shortest round-trip form of their double keep the lexeme: 1.0000000000000001 is no longer double{1.0} and is_integral reports false; exact decimals (0.5, 1.0, 1e-3) still parse as double.
  • Serialization emits the preserved lexeme verbatim (round-trip).
  • allowDecimals still rejects decimal lexemes, in range or not.
  • Helpers: as_number, is_integral, is_finite_number.
  • Downstream: an out-of-range JSON-RPC id now fails as invalid request (non-int64 alternative) instead of a parse error, while unrelated parameters still accept it.
  • Tests: new/updated cases in tests/standalone/Data/StrictJson.cpp. Data+Testing suite: 641 tests, 638 passed, 3 skipped, 0 failed. src/MCP/Envelope.cpp and src/Update/Feed.cpp still compile.
Fixed in 9cb86f8 on `main`. - New `Void::Json::Strict::Number` variant alternative preserves the exact lexeme plus exact `isInteger`, `fitsInt64`/`int64Value`, `Range` (in_range/overflow/underflow) and the nearest `approximate` double. - Grammar-valid numbers outside int64/double range now parse instead of failing: `9223372036854775808`, `-9223372036854775809`, `1e309`, `-1e309`, `1e-400`. - Decimal lexemes that are not the shortest round-trip form of their double keep the lexeme: `1.0000000000000001` is no longer `double{1.0}` and `is_integral` reports false; exact decimals (`0.5`, `1.0`, `1e-3`) still parse as `double`. - Serialization emits the preserved lexeme verbatim (round-trip). - `allowDecimals` still rejects decimal lexemes, in range or not. - Helpers: `as_number`, `is_integral`, `is_finite_number`. - Downstream: an out-of-range JSON-RPC id now fails as invalid request (non-int64 alternative) instead of a parse error, while unrelated parameters still accept it. - Tests: new/updated cases in `tests/standalone/Data/StrictJson.cpp`. Data+Testing suite: 641 tests, 638 passed, 3 skipped, 0 failed. `src/MCP/Envelope.cpp` and `src/Update/Feed.cpp` still compile.
Author
Owner

Verified fixed on main 9cb86f8f978668215328ead51ee6f132552847c1 (2026-12-05): VoidLanguageServer rebuilt against this revision, and the full vls_json_capabilities suite passes, including rounded_fractional_id_cannot_change_lifecycle and valid_number_outside_machine_range_is_still_json. All 12 native test targets pass. Closing.

Verified fixed on main `9cb86f8f978668215328ead51ee6f132552847c1` (2026-12-05): VoidLanguageServer rebuilt against this revision, and the full `vls_json_capabilities` suite passes, including `rounded_fractional_id_cannot_change_lifecycle` and `valid_number_outside_machine_range_is_still_json`. All 12 native test targets pass. Closing.
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Void/Library#60