Skip to content

Commit c9c8195

Browse files
committed
Fix panic on huge integers, closes #139
1 parent 87ed119 commit c9c8195

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "json"
3-
version = "0.11.12"
3+
version = "0.11.13"
44
authors = ["Maciej Hirsz <[email protected]>"]
55
description = "JSON implementation in Rust"
66
repository = "https://github.com/maciejhirsz/json-rust"

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ impl<'a> Parser<'a> {
578578
num.checked_add((ch - b'0') as u64)
579579
}) {
580580
Some(result) => num = result,
581-
None => e += 1 ,
581+
None => e = e.checked_add(1).ok_or_else(|| Error::ExceededDepthLimit)?,
582582
}
583583
},
584584
b'.' => {

tests/parse.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,14 @@ fn does_not_panic_on_single_zero() {
367367

368368
parse(source).unwrap();
369369
}
370+
371+
#[test]
372+
fn does_not_panic_on_huge_numbers() {
373+
let mut string = String::from("8");
374+
375+
for _ in 1..32787 {
376+
string.push('0');
377+
}
378+
379+
let _ = json::parse(&string);
380+
}

0 commit comments

Comments
 (0)