diff --git a/Cargo.toml b/Cargo.toml index c529c57..94bd586 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "json" -version = "0.11.12" +version = "0.11.13" authors = ["Maciej Hirsz "] description = "JSON implementation in Rust" repository = "https://github.com/maciejhirsz/json-rust" diff --git a/src/parser.rs b/src/parser.rs index 0129d93..9e38095 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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'.' => { diff --git a/tests/parse.rs b/tests/parse.rs index f6dc87a..0fe2044 100644 --- a/tests/parse.rs +++ b/tests/parse.rs @@ -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); +}