Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(addresses): Skip error on pointer address overflow #178

Merged
merged 1 commit into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pallas-addresses/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,4 +821,10 @@ mod tests {

assert_eq!(addr.to_bech32().unwrap(), MAINNET_TEST_VECTORS[0].0);
}

#[test]
fn test_minted_invalid_pointed_address() {
let addr = Address::from_hex("40C19D7D05E90EEB6394B53313FE79D47077DE33068C6B813BBE5C9D5681FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7F81FFFFFFFFFFFFFFFF7F81FFFFFFFFFFFFFFFF7F");
assert!(matches!(addr, Ok(Address::Shelley(_))));
}
}
9 changes: 8 additions & 1 deletion pallas-addresses/src/varuint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ pub fn read(cursor: &mut Cursor<&[u8]>) -> Result<u64, Error> {
output = (output << 7) | (byte & 0x7F) as u128;

if output > u64::MAX.into() {
return Err(Error::VarUintOverflow);
// Strictly speaking, if we find a value above max u64, an overflow error should
// be returned. The problem is that testnet has some invalid address values
// somehow minted in valid blocks. The node and many explorers, instead of
// throwing an error, return max u64 as a workaround. We copy the same behavior
// to maintain homogeneity.
//
// return Err(Error::VarUintOverflow);
return Ok(u64::MAX);
}

if (byte & 0x80) == 0 {
Expand Down
2 changes: 2 additions & 0 deletions pallas-primitives/src/alonzo/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,8 @@ mod tests {
include_str!("../../../test_data/alonzo22.block"),
// peculiar block with indef byte array in plutus data
include_str!("../../../test_data/alonzo23.block"),
// peculiar block with invalid address (pointer overflow)
include_str!("../../../test_data/alonzo27.block"),
];

for (idx, block_str) in test_blocks.iter().enumerate() {
Expand Down
1 change: 1 addition & 0 deletions test_data/alonzo27.block

Large diffs are not rendered by default.