Skip to content

Commit

Permalink
rlp: tests: fix 32-bit overflow (#808)
Browse files Browse the repository at this point in the history
the overflow behaviour depends on the width of usize, conditionalize
accordingly.

Fixes: #802

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Co-authored-by: ordian <write@reusable.software>
  • Loading branch information
Fabian-Gruenbichler and ordian authored Jan 2, 2024
1 parent 422471a commit 31e7719
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rlp/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ fn test_rlp_display() {

#[test]
fn length_overflow() {
#[cfg(target_pointer_width = "64")]
let bs = hex!("bfffffffffffffffffffffffe5");
#[cfg(target_pointer_width = "32")]
let bs = hex!("bbffffffffffffffe5");
let rlp = Rlp::new(&bs);
let res: Result<u8, DecoderError> = rlp.as_val();
assert_eq!(Err(DecoderError::RlpInvalidLength), res);
Expand Down Expand Up @@ -593,7 +596,10 @@ fn test_rlp_nested_empty_list_encode() {

#[test]
fn test_rlp_list_length_overflow() {
#[cfg(target_pointer_width = "64")]
let data = hex!("ffffffffffffffffff000000");
#[cfg(target_pointer_width = "32")]
let data = hex!("fbffffffff000000");
let rlp = Rlp::new(&data);
let as_val: Result<String, DecoderError> = rlp.val_at(0);
assert_eq!(Err(DecoderError::RlpIsTooShort), as_val);
Expand Down

0 comments on commit 31e7719

Please sign in to comment.