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

This commit is contained in:
Santiago Carmuega 2022-08-19 22:15:35 -03:00 committed by GitHub
parent f29cc64fd8
commit d94262a3f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 1 deletions

View file

@ -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(_))));
}
}

View file

@ -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 {

View file

@ -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() {

1
test_data/alonzo27.block Normal file

File diff suppressed because one or more lines are too long