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

Illformed giraffe #99

Closed
0xd34d10cc opened this issue Feb 8, 2018 · 2 comments
Closed

Illformed giraffe #99

0xd34d10cc opened this issue Feb 8, 2018 · 2 comments

Comments

@0xd34d10cc
Copy link

0xd34d10cc commented Feb 8, 2018

Cargo.toml:

...

[dependencies]
ramp = "0.3.12"

Code:

extern crate ramp;

use ramp::Int;

static GIRAFFE: &str = 
"
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000001000000000000000000000000000000000000000000
0000000000000000000011000000000000000000000000000000000000000000
0000000000000000000111000000000000000000000000000000000000000000
0000000000000000001111100000000000000000000000000000000000000000
0000000000000000011111100000000000000000000000000000000000000000
0000000000000000011111110000000000000000000000000000000000000000
0000000000000000111111110000000000000000000000000000000000000000
0000000000000000100001111000000000000000000000000000000000000000
0000000000000000000000111000000000000000000000000000000000000000
0000000000000000000000111100000000000000000000000000000000000000
0000000000000000000000011110000000000000000000000000000000000000
0000000000000000000000011110000000000000000000000000000000000000
0000000000000000000000001111000000000000000000000000000000000000
0000000000000000000000001111100000000000000000000000000000000000
0000000000000000000000000111110000000000000000000000000000000000
0000000000000000000000000111111000000000000000000000000000000000
0000000000000000000000000011111110000000000000000000000000000000
0000000000000000000000000011111111100000000000000000000000000000
0000000000000000000000000001111111111000000000000000000000000000
0000000000000000000000000001111111111100000000000000000000000000
0000000000000000000000000000111111111111000000000000000000000000
0000000000000000000000000000011111111111111000000000000000000000
0000000000000000000000000000011111111111111110000000000000000000
0000000000000000000000000000011111111111111111000000000000000000
0000000000000000000000000000011111111111111111100000000000000000
0000000000000000000000000000011111111111111111100000000000000000
0000000000000000000000000000011111111111111111110000000000000000
0000000000000000000000000000011111111111111111110000000000000000
0000000000000000000000000000001111111111111111110000000000000000
0000000000000000000000000000001111111111111111110000000000000000
0000000000000000000000000000001111000011111111100000000000000000
0000000000000000000000000000001111000001111111100000000000000000
0000000000000000000000000000001111000000111111100000000000000000
0000000000000000000000000000011111000000111111100000000000000000
0000000000000000000000000000011011000000011011100000000000000000
0000000000000000000000000000011011000000011101110000000000000000
0000000000000000000000000000110011000000011101110000000000000000
0000000000000000000000000000110011000000011100111000000000000000
0000000000000000000000000000110011000000011100110000000000000000
0000000000000000000000000000110011000000011000110000000000000000
0000000000000000000000000000011001000000010000110000000000000000
0000000000000000000000000000001001000000110000110000000000000000
0000000000000000000000000000000111000000100000110000000000000000
0000000000000000000000000000000111000001100000110000000000000000
0000000000000000000000000000000011000011000000110000000000000000
0000000000000000000000000000000011000011000000110000000000000000
0000000000000000000000000000000011100110000000110000000000000000
0000000000000000000000000000000011100110000000110000000000000000
0000000000000000000000000000000010100110000000100000000000000000
0000000000000000000000000000000110000000000001100000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
";

fn main() {
    let input: String = GIRAFFE.chars()
        .filter(|c| !c.is_whitespace())
        .collect();

    let x = Int::from_str_radix(&input, 2).unwrap();
    println!("{}", x);
}

Output:

$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/illformed-giraffe`
thread 'main' panicked at 'assertion failed: self.well_formed()', /home/d34d10cc/.cargo/registry/src/github.com-1ecc6299db9ec823/ramp-0.3.12/src/int.rs:314:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Expected output:

342581792649127676198127791406119644054852809184750511204770992210601825938383173228625368612512343524580568135765381129832784929140287102447656231670490278371618738040053550924844754083137995849927287014555199009052294292243605111352278964229602623894816760629354416193979550552423279842373621548435137856781153105076831681645952473068169294190544029391463758663828828100567003458546392021905815042131115480711892076216081858013250696070743624005842779807059777397154653840706692288630135185563366228931093496037459868457738024280865863648682544327375771172685872176976999577303715645442779935499071380556380855234358517399907184246818275843840363379983214925406281243183361618849192180391506653641933784053451121171160334712857092937535606122822893204604775038632348974223351004456787673186165100098223897371450275291114458983950607846718107603195397991880820766444935587675531082421404505700110617860358142315360174185418283092141238404865012380329781867103175076882601367389664213176688432343205501275425887396821357210158983064167712232404771958406106398750988506833703615072967113834496
@0xd34d10cc
Copy link
Author

0xd34d10cc commented Feb 8, 2018

Minimal example:

fn main() {
    use std::iter;

    let num: String = iter::repeat('0')
        .take(64)
        .collect();

    let x = Int::from_str_radix(&num, 2).unwrap();
    println!("{}", x);
}

Assertion fails because most significant Limb is zero. That happened because Int::from_str_radix doesn't consider leading zeros.

@rozbb
Copy link
Collaborator

rozbb commented Jun 18, 2018

Solved by #100

@rozbb rozbb closed this as completed Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants