From 120970ccd70b1e8eb3867fc2b511c1967eaaabbb Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 23 Mar 2019 13:45:54 +0100 Subject: Handle double overflows in parser --- dhall_core/src/parser.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'dhall_core') diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs index 9fd3213..9b73bfd 100644 --- a/dhall_core/src/parser.rs +++ b/dhall_core/src/parser.rs @@ -355,10 +355,15 @@ make_parser! { rule!(double_literal_raw; raw_pair!(pair) => { - pair.as_str().trim() - .parse::() - .map(NaiveDouble::from) - .map_err(|e: std::num::ParseFloatError| custom_parse_error(&pair, format!("{}", e)))? + let s = pair.as_str().trim(); + match s.parse::() { + Ok(x) if x.is_infinite() => + Err(custom_parse_error(&pair, + format!("Overflow while parsing double literal '{}'", s) + ))?, + Ok(x) => NaiveDouble::from(x), + Err(e) => Err(custom_parse_error(&pair, format!("{}", e)))?, + } } ); -- cgit v1.2.3