Boost Spirit parser input

I have a parser that uses a numeric parser qi::double_

. I have a case where user data contains a uuid string:

"00573e443ef1ec10b5a1f23ac8a69c43c415cedf"

And I am getting crashing inside the ghost function pow10_helper()

below. Testing a little more seems to happen for any line, starting with a number followed by e

another number. For example, it 1e999

also falls. To reproduce the crash, try:

#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
int main()
{
    double x;
    std::string s = "1e999";
    auto a = s.begin();
    auto b = s.end();
    qi::parse(a, b, qi::double_, x); // <--- crash/assert in debug mode
}

      

I use spirit because of its raw performance ( qi::double_

about 2x faster than strtod()

). My question is, is there a way to get around this limitation? Moving to a slower parser will be painful, but let me know if you have any special suggestions.

Relevant formatting code fails ( boost/spirit/home/support/detail/pow10.hpp

) for reference:

template <>
struct pow10_helper<double>
{
    static double call(unsigned dim)
    {
        static double const exponents[] =
        {
            1e0,   1e1,   1e2,   1e3,   1e4,   1e5,   1e6,   1e7,   1e8,    1e9,
            ...
            1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306, 1e307, 1e308,
        };
        BOOST_ASSERT(dim < sizeof(exponents)/sizeof(double));
        return exponents[dim]; // <--- crash here, dim is 999 which is >308
    }
};

      

As a side note, this seems like a huge mistake in spirit implementation. You should be able to easily dump any ghost app that parses doubles by passing a dummy input, for example 1e999

.

+3


source to share


1 answer


This is a known issue and has been fixed in 1_57_0 AFAIR

The mailing list is discussed here:



On November 7, Joel de Guzman wrote:

This is now being committed to the development branch along with integer improvements in floating point precision analysis (corner cases). There are some backward incompatible changes, but they should affect those who use the real parser policy, in the patristic, those who specialize in parse_frac_n. Changes will be documented in a timely manner.

+3


source







All Articles