-
Notifications
You must be signed in to change notification settings - Fork 789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing of long floating point numbers causes panic #1421
Comments
thanks for the report. Could you test with nom directly from master? |
Sure.
I did a git clone, current master HEAD is at dfa5591, and then specified nom dependency as path
|
I got the same panic using |
Here's the workaround I'm using for now. It's a bit of a cudgel, but afaict it gets the old behavior back. /// This is derived from nom::number::complete::float, which is unfortunately broken in nom 7.0.0.
/// - https://github.com/Geal/nom/issues/1421
/// - https://github.com/Geal/nom/issues/1384
pub fn float<T, E: ParseError<T>>(input: T) -> IResult<T, f32, E>
where
T: nom::Slice<std::ops::RangeFrom<usize>>
+ nom::Slice<std::ops::RangeTo<usize>>
+ nom::Slice<std::ops::Range<usize>>,
T: Clone + nom::Offset,
T: nom::InputIter + nom::InputLength + nom::InputTake,
<T as nom::InputIter>::Item: nom::AsChar + Copy,
<T as nom::InputIter>::IterElem: Clone,
T: nom::InputTakeAtPosition,
<T as nom::InputTakeAtPosition>::Item: nom::AsChar,
T: nom::AsBytes,
T: for<'a> nom::Compare<&'a [u8]>,
T: nom::ParseTo<f32>,
T: nom::InputTake + nom::Compare<&'static str>,
{
let (i, s) = recognize_float(input)?;
match s.parse_to() {
Some(f) => (Ok((i, f))),
None => Err(nom::Err::Error(E::from_error_kind(
i,
nom::error::ErrorKind::Float,
))),
}
}
pub fn recognize_float<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
where
T: nom::Slice<std::ops::RangeFrom<usize>> + nom::Slice<std::ops::RangeTo<usize>>,
T: Clone + nom::Offset,
T: nom::InputIter,
<T as nom::InputIter>::Item: nom::AsChar,
T: nom::InputTakeAtPosition,
<T as nom::InputTakeAtPosition>::Item: nom::AsChar,
T: nom::InputTake + nom::Compare<&'static str>,
{
alt((
nom::number::complete::recognize_float,
nom::combinator::recognize(nom::bytes::complete::tag("NaN")),
))(input)
} |
This should have been closed by #1455 |
Yes. Leaving it open for now, I'd like to get a proper fix in minimal-lexical, because we take a perf hit with that workaround |
Might as well avoid the dep until rust-bakery/nom#1421 is fixed which is blocked on Alexhuszagh/minimal-lexical#7
Might as well avoid the dep until rust-bakery/nom#1421 is fixed which is blocked on Alexhuszagh/minimal-lexical#7
Hello, first of all thank you, nom is a great tool!
I have tried to migrate to a new nom version (7.0.0) and encountered some unexpected behavior.
float
,double
) panics for long inputs6.*
versions does not panicAfter a little digging, I think this is caused by switching to
minimal-lexical
.Somewhat related to #1384
Prerequisites
rustc 1.55.0 (c8dfcfe04 2021-09-06)
also tried it with nightlyv7.0.0
Test case
nom
v7.0.0
nom
v6.2.1
The text was updated successfully, but these errors were encountered: