From 90040b34b69fe6c94a9f1dcd0bbc8372f0f14d13 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Wed, 31 May 2017 00:07:15 +0100 Subject: [PATCH] Error when parsing numbers outside of f64's range --- src/de.rs | 6 ++++++ tests/invalid-misc.rs | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/de.rs b/src/de.rs index bd4ead0..d5af272 100644 --- a/src/de.rs +++ b/src/de.rs @@ -893,6 +893,12 @@ impl<'a> Deserializer<'a> { } number.parse().map_err(|_e| { self.error(start, ErrorKind::NumberInvalid) + }).and_then(|n: f64| { + if n.is_finite() { + Ok(n) + } else { + Err(self.error(start, ErrorKind::NumberInvalid)) + } }) } diff --git a/tests/invalid-misc.rs b/tests/invalid-misc.rs index 53f625e..bb70b97 100644 --- a/tests/invalid-misc.rs +++ b/tests/invalid-misc.rs @@ -10,4 +10,8 @@ fn bad() { bad("a = 1__1"); bad("a = 1_"); bad("''"); + bad("a = nan"); + bad("a = -inf"); + bad("a = inf"); + bad("a = 9e99999"); }