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

TOB-FUEL-33: Decoding of TxPointer with multibyte characters might panic #567

Closed
xgreenx opened this issue Aug 28, 2023 · 1 comment
Closed
Labels
audit-report Issue from the audit report

Comments

@xgreenx
Copy link
Collaborator

xgreenx commented Aug 28, 2023

Description

The decoding of a TxPointer might panic if the input string contains multi-byte characters. The following code shows a unit test which panics.

Figure 33.1: Unit test that panics.

#[test]
fn panic_slice() {
TxPointer::from_str(&"0000000 0").expect("failed to decode from str"); 😎
}

The next figure highlights the string-slice operation which causes the panic.

Figure 33.2: Decoding function from strings to TxPointer. (fuel-vm/fuel-tx/src/tx_pointer.rs/#92–107)

impl str::FromStr for TxPointer {
    type Err = &'static str;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        const ERR: &str = "Invalid encoded byte";
        if s.len() != 12 {
            return Err(ERR)
        }
        let block_height = u32::from_str_radix(
        let tx_index = u16::from_str_radix(&
        Ok(Self::new(block_height.into(), tx_index))
    }
}

Recommendations

Short term, verify that the input for the TxPointer parsing function contains only single byte characters.
Long term, consider enabling the Clippy rule string_slice.

@xgreenx xgreenx added the audit-report Issue from the audit report label Aug 28, 2023
@xgreenx xgreenx closed this as completed Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit-report Issue from the audit report
Projects
None yet
Development

No branches or pull requests

1 participant