Skip to content

Unsafe unwrap could cause an application to panic Β #282

@kevin-valerio

Description

@kevin-valerio

return Ok(decode::u64(&b[..=i]).unwrap().0);

The unwrap() here might cause some crash using the library if an error occurred. For chains using Substrate, this could cause critical severity issues if an attacker is able to craft a malicious payload in order to trigger the unwrap.

You can find an image of a malicious payload that will cause a panic below.
image

Below is an example of a fix that could be used :

   if decode::is_last(b[i]) {
      match decode::u64(&b[..=i]) {
        Ok(val) => return Ok(val.0),
        Err(_) => return Err(Error::VarIntDecodeError),
      }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions