This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 948706b  fix: Don't silently truncate numbers larger than `i64::MAX` 
when converting from JSON (#450)
948706b is described below

commit 948706b869f3700e15b0f98d10a30029f7bb40c7
Author: Kriskras99 <[email protected]>
AuthorDate: Sat Jan 31 12:26:47 2026 +0100

    fix: Don't silently truncate numbers larger than `i64::MAX` when converting 
from JSON (#450)
---
 avro/src/types.rs | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/avro/src/types.rs b/avro/src/types.rs
index 0060987..e375f71 100644
--- a/avro/src/types.rs
+++ b/avro/src/types.rs
@@ -145,7 +145,7 @@ to_value!(f32, Value::Float);
 to_value!(f64, Value::Double);
 to_value!(String, Value::String);
 to_value!(Vec<u8>, Value::Bytes);
-to_value!(uuid::Uuid, Value::Uuid);
+to_value!(Uuid, Value::Uuid);
 to_value!(Decimal, Value::Decimal);
 to_value!(BigDecimal, Value::BigDecimal);
 to_value!(Duration, Value::Duration);
@@ -283,7 +283,7 @@ impl From<JsonValue> for Value {
                 }
             }
             JsonValue::Number(ref n) if n.is_f64() => 
Value::Double(n.as_f64().unwrap()),
-            JsonValue::Number(n) => Value::Long(n.as_u64().unwrap() as i64), 
// TODO: Not so great
+            JsonValue::Number(n) => panic!("{n:?} does not fit into an Avro 
long"),
             JsonValue::String(s) => s.into(),
             JsonValue::Array(items) => 
Value::Array(items.into_iter().map(Value::from).collect()),
             JsonValue::Object(items) => Value::Map(
@@ -3240,7 +3240,6 @@ Field with name '"b"' is not a member of the map items"#,
         assert_eq!(Value::from(json!(1.23)), Value::Double(1.23));
         assert_eq!(Value::from(json!(-1.23)), Value::Double(-1.23));
         assert_eq!(Value::from(json!(u64::MIN)), Value::Int(u64::MIN as i32));
-        assert_eq!(Value::from(json!(u64::MAX)), Value::Long(u64::MAX as i64));
         assert_eq!(
             Value::from(json!("some text")),
             Value::String("some text".into())
@@ -3500,4 +3499,10 @@ Field with name '"b"' is not a member of the map items"#,
             Details::ZagI32(_, _)
         ));
     }
+
+    #[test]
+    #[should_panic(expected = "Number(18446744073709551615) does not fit into 
an Avro long")]
+    fn avro_rs_450_serde_json_number_u64_max() {
+        let _ = Value::from(json!(u64::MAX));
+    }
 }

Reply via email to