From 8562d18cd07a84681961c5660c22f481f7f7dc8f Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 14 Oct 2015 11:03:07 +0100 Subject: [PATCH] geoson.input - throw an exception if input hasn't been fully consumed --- plugins/input/geojson/geojson_datasource.cpp | 9 ++++++--- plugins/input/geojson/large_geojson_featureset.cpp | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index ea3f30bfa..b37973445 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -202,7 +202,8 @@ void geojson_datasource::initialise_index(Iterator start, Iterator end) mapnik::json::boxes_type boxes; boost::spirit::standard::space_type space; Iterator itr = start; - if (!boost::spirit::qi::phrase_parse(itr, end, (geojson_datasource_static_bbox_grammar)(boost::phoenix::ref(boxes)) , space)) + if (!boost::spirit::qi::phrase_parse(itr, end, (geojson_datasource_static_bbox_grammar)(boost::phoenix::ref(boxes)) , space) + || itr != end) { throw mapnik::datasource_exception("GeoJSON Plugin: could not parse: '" + filename_ + "'"); } @@ -222,7 +223,9 @@ void geojson_datasource::initialise_index(Iterator start, Iterator end) Iterator end2 = itr2 + geometry_index.second; mapnik::context_ptr ctx = std::make_shared(); mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,1)); - if (!boost::spirit::qi::phrase_parse(itr2, end2, (geojson_datasource_static_feature_grammar)(boost::phoenix::ref(*feature)), space)) + if (!boost::spirit::qi::phrase_parse(itr2, end2, + (geojson_datasource_static_feature_grammar)(boost::phoenix::ref(*feature)), space) + || itr2 != end2) { throw std::runtime_error("Failed to parse geojson feature"); } @@ -252,7 +255,7 @@ void geojson_datasource::parse_geojson(Iterator start, Iterator end) bool result = boost::spirit::qi::phrase_parse(start, end, (geojson_datasource_static_fc_grammar) (boost::phoenix::ref(ctx),boost::phoenix::ref(start_id), boost::phoenix::ref(callback)), space); - if (!result) + if (!result || start != end) { if (!inline_string_.empty()) throw mapnik::datasource_exception("geojson_datasource: Failed parse GeoJSON file from in-memory string"); else throw mapnik::datasource_exception("geojson_datasource: Failed parse GeoJSON file '" + filename_ + "'"); diff --git a/plugins/input/geojson/large_geojson_featureset.cpp b/plugins/input/geojson/large_geojson_featureset.cpp index 6f61d53c7..24709538a 100644 --- a/plugins/input/geojson/large_geojson_featureset.cpp +++ b/plugins/input/geojson/large_geojson_featureset.cpp @@ -65,13 +65,12 @@ mapnik::feature_ptr large_geojson_featureset::next() using chr_iterator_type = char const*; chr_iterator_type start = json.data(); chr_iterator_type end = start + json.size(); - static const mapnik::transcoder tr("utf8"); static const mapnik::json::feature_grammar grammar(tr); using namespace boost::spirit; standard::space_type space; mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,1)); - if (!qi::phrase_parse(start, end, (grammar)(boost::phoenix::ref(*feature)), space)) + if (!qi::phrase_parse(start, end, (grammar)(boost::phoenix::ref(*feature)), space) || start != end) { throw std::runtime_error("Failed to parse geojson feature"); }