-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from Chia-Network/sanitize-int
sanitize_uint improvement
- Loading branch information
Showing
6 changed files
with
161 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#![no_main] | ||
use libfuzzer_sys::fuzz_target; | ||
|
||
use clvmr::allocator::Allocator; | ||
use chia::gen::sanitize_int::{sanitize_uint, SanitizedUint}; | ||
use chia::gen::validation_error::{ErrorCode, ValidationErr}; | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
let mut a = Allocator::new(); | ||
let atom = a.new_atom(data).unwrap(); | ||
match sanitize_uint(&a, atom, 8, ErrorCode::InvalidCoinAmount) { | ||
Ok(SanitizedUint::Ok(_)) => { | ||
assert!(data.len() <= 9); | ||
if data.len() == 9 { | ||
assert!(data[0] == 0); | ||
} | ||
}, | ||
Ok(SanitizedUint::NegativeOverflow) => { | ||
assert!(data.len() > 0 && (data[0] & 0x80) != 0); | ||
}, | ||
Ok(SanitizedUint::PositiveOverflow) => { | ||
assert!(data.len() > 8); | ||
}, | ||
Err(ValidationErr(n, c)) => { | ||
assert!(n == atom); | ||
assert!(c == ErrorCode::InvalidCoinAmount); | ||
} | ||
} | ||
|
||
match sanitize_uint(&a, atom, 4, ErrorCode::InvalidCoinAmount) { | ||
Ok(SanitizedUint::Ok(_)) => { | ||
assert!(data.len() <= 5); | ||
if data.len() == 5 { | ||
assert!(data[0] == 0); | ||
} | ||
}, | ||
Ok(SanitizedUint::NegativeOverflow) => { | ||
assert!(data.len() > 0 && (data[0] & 0x80) != 0); | ||
}, | ||
Ok(SanitizedUint::PositiveOverflow) => { | ||
assert!(data.len() > 4); | ||
}, | ||
Err(ValidationErr(n, c)) => { | ||
assert!(n == atom); | ||
assert!(c == ErrorCode::InvalidCoinAmount); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.