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 1f0eb3bfc0
commit ce6c13b5f5
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 {