Skip to content

out of range integral type conversion attempted on legal numbers #139

@renier

Description

@renier

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 --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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions