influxdata / influxdata/pbjson
out of range integral type conversion attempted on legal numbers
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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