influxdata / influxdata/pbjson

out of range integral type conversion attempted on legal numbers

Open
#139 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
116
Forks
55
PR merge metrics
No merged PRs in 30d

Description

I'm getting `out of range integral type conversion attempted` errors when the deserializer sees numbers with more than 16 digits.

Updating the value::tests:number test in this way exposes the issue:
```diff
diff --git a/pbjson-types/src/value.rs b/pbjson-types/src/value.rs
index c3fc87b..14d9fc2 100644
--- a/pbjson-types/src/value.rs
+++ b/pbjson-types/src/value.rs
@@ -321,6 +321,8 @@ mod tests {
serde_json::to_value(Value::from(5.0)).unwrap(),
serde_json::json!(5.0)
);
+ let val: Value = serde_json::from_str("13241173089000000").unwrap();
+ assert_eq!(val, Value::from(13241173089000000f64))
}

#[test]
```

That test addition results in:
```
---- value::tests::number stdout ----
thread 'value::tests::number' panicked at pbjson-types/src/value.rs:324:68:
called `Result::unwrap()` on an `Err` value: Error("out of range integral type conversion attempted", line: 1, column: 17)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

I understand there was a related fix (#87) last year. However, this fails with larger numbers which are still well within the min/max range for floating numbers in Rust, as the number in the above test modification.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with pbjson-types/src/value.rs and the value::tests::number test, using the provided 17-digit input to reproduce the deserialization failure. Trace the number conversion involved and extend the test coverage for larger legal floating-point values. Done means the test passes and the reported value matches Value::from(13241173089000000f64).

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.