Skip to content

Commit 95e8dbd

Browse files
authored
Merge pull request #330 from Concordium/feature/verifier-add-validation-error-for-i64-exepcted-negative
fix: add validation error as a precaution when an i64 is not negative…
2 parents 548cd67 + 6078097 commit 95e8dbd

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

credential-verification-service/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Unreleased
22

3+
- add check to ensure number is negative for public info number checking for cases where we tried the literal as a u64 first.
4+
35
## 0.3.1
46

57
- fix for precision integer handling in the correct range for public info. Range supported for: `-9223372036854775808` -> `18446744073709551615`

credential-verification-service/src/api/util.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,22 @@ fn json_to_cbor_value(value: &serde_json::Value) -> Result<cbor::value::Value, V
6262
// postive number that fits in u64
6363
cbor::value::Value::Positive(posint)
6464
} else if let Some(negint) = n.as_i64() {
65-
// this number is definitely negative
65+
// this number should definitely be negative as above we test
66+
// if we are in the u64 range: 0 -> u64::max. i64 is a smaller
67+
// range than u64 so `n` should always be negative reaching
68+
// this point. Error if >= 0.
69+
if negint >= 0 {
70+
return Err(ValidationError {
71+
details: vec![ErrorDetail {
72+
code: "PUBLIC_INFO_NUMBER_PARSE_ISSUE".to_string(),
73+
message: format!(
74+
"Number was treated as i64 and expected to be negative at this point. {:?}",
75+
n
76+
),
77+
path: "publicInfo".to_string(),
78+
}],
79+
});
80+
}
6681
let negintmag: u64 = (-1i64 - negint) as u64;
6782
cbor::value::Value::Negative(negintmag)
6883
} else if let Some(float) = n.as_f64() {

0 commit comments

Comments
 (0)