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

Decoding of UtxoId with multibyte characters can panic #521

Closed
Dentosal opened this issue Jul 25, 2023 · 0 comments · Fixed by #531
Closed

Decoding of UtxoId with multibyte characters can panic #521

Dentosal opened this issue Jul 25, 2023 · 0 comments · Fixed by #531
Assignees
Labels
bug Something isn't working fuel-tx Related to the `fuel-tx` crate. good first issue Good for newcomers

Comments

@Dentosal
Copy link
Member

The following query panics:

{ 
 coin(utxoId:  "0x00😎"  )  {  utxoId  } 
}

This is caused by careless use of string indexing here:

fn from_str(s: &str) -> Result<Self, Self::Err> {
const ERR: &str = "Invalid encoded byte";
let s = s.trim_start_matches("0x");
let utxo_id = if s.is_empty() {
UtxoId::new(Bytes32::default(), 0)
} else if s.len() > 2 {
UtxoId::new(
Bytes32::from_str(&s[..s.len() - 2])?,
u8::from_str_radix(&s[s.len() - 2..], 16).map_err(|_| ERR)?,
)
} else {
UtxoId::new(TxId::default(), u8::from_str_radix(s, 16).map_err(|_| ERR)?)
};
Ok(utxo_id)
}

We should probably use #[deny(clippy::string_slice)] to avoid these issues in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fuel-tx Related to the `fuel-tx` crate. good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant