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

[Bug] Dynamic data may cause decode_single to panic #170

Closed
Philogy opened this issue Jul 3, 2023 · 1 comment · Fixed by #172
Closed

[Bug] Dynamic data may cause decode_single to panic #170

Philogy opened this issue Jul 3, 2023 · 1 comment · Fixed by #172
Assignees
Labels
bug Something isn't working

Comments

@Philogy
Copy link

Philogy commented Jul 3, 2023

Component

dyn-abi

What version of Alloy are you on?

v0.2.0 commit ca37a23

Operating System

Linux

Describe the bug

Description

DynSolType::decode_single will panic when it encounters certain data.

Expected Behavior vs. Actual Behavior

Expected decode_single to result in a Result::Err(..) value if it's unable to decode given data, instead it panics bringing the whole program to a halt.

How to reproduce:

Run the following snippet

use alloy_dyn_abi::DynSolType;
use hex_literal::hex;
use std::string::String;

fn main() -> Result<(), String> {
    let my_type: DynSolType = "(string[],bytes13,bytes13[2])"
        .parse()
        .map_err(|err| format!("Failed to parse: {}", err))?;
    let decoded = my_type
        .decode_single(&hex!(
            "

0000000000000000000000000000000000000000000000000000000000000080
93dd71318b60d9fa85991e714900000000000000000000000000000000000000
4f1a284fd349323201bfb3e41a00000000000000000000000000000000000000
b99bf51f6dbbddbea4defb6b1000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000002
0000000000000000000000000000000000000000000000000000000000000040
0000000000000000000000000000000000000000000000000000000000000080
000000000000000000000000000000000000000000000000000000000000001f
755f382c5a725e095a4d4c57244f433f0d3435360d335d766b712850594a5300
0000000000000000000000000000000000000000000000000000000000000010
475e6272723d456b49225f095e51432b00000000000000000000000000000000
"
        ))
        .map_err(|err| format!("Failed to decode: {}", err));
    println!("decoded: {decoded:?}");

    Ok(())
}

It should result in the following panic:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Overrun', /home/philippe/.cargo/git/checkouts/core-3f428e9ca4699f0e/ca37a23/crates/dyn-abi/src/token.rs:169:65
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Note the above data is valid and will be decoded successfully by decode_params and decode_sequence.

@Philogy Philogy added the bug Something isn't working label Jul 3, 2023
@prestwich
Copy link
Member

prestwich commented Jul 3, 2023

Fixed in #172

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants