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

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

commit 24a30106b86b9ce873e71ac13f62e466a2872d69
Author: Kriskras99 <[email protected]>
AuthorDate: Wed Jan 7 15:43:19 2026 +0100

    fix: Resolving a `Long` to an `Int` silently truncates
---
 avro/src/types.rs | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/avro/src/types.rs b/avro/src/types.rs
index 02a5a8e..317cec5 100644
--- a/avro/src/types.rs
+++ b/avro/src/types.rs
@@ -903,7 +903,10 @@ impl Value {
     fn resolve_int(self) -> Result<Self, Error> {
         match self {
             Value::Int(n) => Ok(Value::Int(n)),
-            Value::Long(n) => Ok(Value::Int(n as i32)),
+            Value::Long(n) => {
+                let n = i32::try_from(n).map_err(|e| Details::ZagI32(e, n))?;
+                Ok(Value::Int(n))
+            }
             other => Err(Details::GetInt(other).into()),
         }
     }

Reply via email to