Skip to content

BigUint::from_str_radix panics with invalid string containing "+" #268

Closed

Description

@birkenfeld

Test case:

use num_traits::Num;
num_bigint::BigUint::from_str_radix("0+2", 10);

will panic instead of returning an Err:

stack backtrace:
...
  10:     0x5629031d9e61 - <core::result::Result<T, E>>::unwrap_err::ha2ff9ebcf57c662c
                        at /checkout/src/libcore/result.rs:789
  11:     0x5629031e38db - <num_bigint::biguint::BigUint as num_traits::Num>::from_str_radix::h2b33fa225070b5b3
                        at .../num-bigint-0.1.36/src/biguint.rs:245

Cause is that num tries to create and unwrap_err a ParseIntError from std by calling parse on s[i..] where i is the index of the +. This will not error out if there are only valid digits after the +.

@Manishearth for the trophy case - found by using cargo-fuzz on serde-pickle

Activity

  1. added a commit that references this issue on Mar 6, 2017
    0b6cae0
  2. added a commit that references this issue on Mar 8, 2017
    fe21c72
  3. cuviper commented on Mar 8, 2017

    @cuviper
    Member

    Thanks, reports like this are welcome! This is now fixed and published in num-bigint v0.1.37.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions