From 6e9c56ee2c8264a6ca0c89d22756661c414bf458 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Mon, 11 Sep 2017 17:28:09 +0100 Subject: [PATCH 1/2] geojson.input - check and throw if bounding box extrator returns no boxes and not all input consumed (preserve 3.0.x caps) --- plugins/input/geojson/geojson_datasource.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index 7bbf54627..e39b98047 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -272,6 +272,7 @@ void geojson_datasource::initialise_index(Iterator start, Iterator end) try { mapnik::json::extract_bounding_boxes(itr, end, boxes); + if (itr != end || boxes.empty()) throw std::exception(); // bulk insert initialise r-tree tree_ = std::make_unique(boxes); // calculate total extent @@ -363,9 +364,7 @@ void geojson_datasource::parse_geojson(Iterator start, Iterator end) { boxes_type boxes; mapnik::json::extract_bounding_boxes(itr, end, boxes); - - if (itr != end) throw std::runtime_error("Malformed GeoJSON"); //ensure we've consumed all input - + if (itr != end || boxes.empty()) throw std::exception(); //ensure we've consumed all input and we extracted at least one bbox; for (auto const& item : boxes) { auto const& geometry_index = std::get<1>(item); From 04f9db4b189530b12b9a62c7e4bc0509e4150dc5 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Mon, 11 Sep 2017 17:30:37 +0100 Subject: [PATCH 2/2] minor format --- include/mapnik/geom_util.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mapnik/geom_util.hpp b/include/mapnik/geom_util.hpp index 8dea3d16f..63e69c8cf 100644 --- a/include/mapnik/geom_util.hpp +++ b/include/mapnik/geom_util.hpp @@ -155,14 +155,14 @@ inline double point_to_segment_distance(double x, double y, return distance(x,y,ax,ay); } - double r = ((x - ax)*(bx - ax) + (y - ay)*(by -ay))/len2; + double r = ((x - ax)*(bx - ax) + (y - ay)*(by - ay))/len2; if ( r < 0 ) { return distance(x,y,ax,ay); } else if (r > 1) { - return distance(x,y,bx,by); + return distance(x, y, bx, by); } double s = ((ay - y)*(bx - ax) - (ax - x)*(by - ay))/len2; return std::fabs(s) * std::sqrt(len2);