Skip to content

Commit 60eb2fd

Browse files
authored
fix(protocol): Correctly deserialize large unsigned values (#4472)
Fixes: #4469
1 parent ea156e9 commit 60eb2fd

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
- Add flags context to event schema. ([#4458](https://github.com/getsentry/relay/pull/4458))
99
- Add support for view hierarchy attachment scrubbing. ([#4452](https://github.com/getsentry/relay/pull/4452))
1010

11+
**Bug Fixes**:
12+
13+
- Fix a bug where parsing large unsigned integers would fail incorrectly. ([#4472](https://github.com/getsentry/relay/pull/4472))
14+
1115
**Internal**:
1216

1317
- Add data categories for LogItem and LogByte. ([#4455](https://github.com/getsentry/relay/pull/4455))

relay-protocol/src/value.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,10 @@ impl<'de> Deserialize<'de> for Value {
265265

266266
#[inline]
267267
fn visit_u64<E>(self, value: u64) -> Result<Value, E> {
268-
let signed_value = value as i64;
269-
if signed_value as u64 == value {
270-
Ok(Value::I64(signed_value))
271-
} else {
272-
Ok(Value::U64(value))
273-
}
268+
Ok(value
269+
.try_into()
270+
.map(Value::I64)
271+
.unwrap_or(Value::U64(value)))
274272
}
275273

276274
#[inline]
@@ -504,3 +502,17 @@ impl PartialEq for Val<'_> {
504502
}
505503
}
506504
}
505+
506+
#[cfg(test)]
507+
mod tests {
508+
use super::*;
509+
510+
#[test]
511+
fn test_unsigned_signed() {
512+
let v: Value = serde_json::from_str("9223372036854775816").unwrap();
513+
assert_eq!(v, Value::U64(9223372036854775816));
514+
515+
let v: Value = serde_json::from_str("123").unwrap();
516+
assert_eq!(v, Value::I64(123));
517+
}
518+
}

0 commit comments

Comments
 (0)