Skip to content

Commit

Permalink
fix(protocol): Correctly deserialize large unsigned values (#4472)
Browse files Browse the repository at this point in the history
Fixes: #4469
  • Loading branch information
Dav1dde authored Jan 24, 2025
1 parent ea156e9 commit 60eb2fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- Add flags context to event schema. ([#4458](https://github.com/getsentry/relay/pull/4458))
- Add support for view hierarchy attachment scrubbing. ([#4452](https://github.com/getsentry/relay/pull/4452))

**Bug Fixes**:

- Fix a bug where parsing large unsigned integers would fail incorrectly. ([#4472](https://github.com/getsentry/relay/pull/4472))

**Internal**:

- Add data categories for LogItem and LogByte. ([#4455](https://github.com/getsentry/relay/pull/4455))
Expand Down
24 changes: 18 additions & 6 deletions relay-protocol/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,10 @@ impl<'de> Deserialize<'de> for Value {

#[inline]
fn visit_u64<E>(self, value: u64) -> Result<Value, E> {
let signed_value = value as i64;
if signed_value as u64 == value {
Ok(Value::I64(signed_value))
} else {
Ok(Value::U64(value))
}
Ok(value
.try_into()
.map(Value::I64)
.unwrap_or(Value::U64(value)))
}

#[inline]
Expand Down Expand Up @@ -504,3 +502,17 @@ impl PartialEq for Val<'_> {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_unsigned_signed() {
let v: Value = serde_json::from_str("9223372036854775816").unwrap();
assert_eq!(v, Value::U64(9223372036854775816));

let v: Value = serde_json::from_str("123").unwrap();
assert_eq!(v, Value::I64(123));
}
}

0 comments on commit 60eb2fd

Please sign in to comment.