Skip to content

Commit

Permalink
Fix panic on huge integers, closes #139
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejhirsz committed Jan 17, 2018
1 parent 87ed119 commit c9c8195
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "json"
version = "0.11.12"
version = "0.11.13"
authors = ["Maciej Hirsz <maciej.hirsz@gmail.com>"]
description = "JSON implementation in Rust"
repository = "https://github.com/maciejhirsz/json-rust"
Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ impl<'a> Parser<'a> {
num.checked_add((ch - b'0') as u64)
}) {
Some(result) => num = result,
None => e += 1 ,
None => e = e.checked_add(1).ok_or_else(|| Error::ExceededDepthLimit)?,
}
},
b'.' => {
Expand Down
11 changes: 11 additions & 0 deletions tests/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,14 @@ fn does_not_panic_on_single_zero() {

parse(source).unwrap();
}

#[test]
fn does_not_panic_on_huge_numbers() {
let mut string = String::from("8");

for _ in 1..32787 {
string.push('0');
}

let _ = json::parse(&string);
}

0 comments on commit c9c8195

Please sign in to comment.