From 51fbb4fcbdb68250f973b3cd7865c65cf8150952 Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Tue, 2 May 2017 11:08:26 +0200 Subject: [PATCH] Fixes Table not checking for valid phantom nodes We failed to check if we could actually find phantom nodes for all coordinates in the table plugin, leading to corrupt internal state. ``` curl 'http://localhost:5000/table/v1/car/7.4151,43.7305;7.4222,43.7368?radiuses=0;' ``` ``` [assert][140505627227904] /tmp/osrm-backend/include/engine/routing_algorithms/routing_base.hpp:68 in: void osrm::engine::routing_algorithms::insertNodesInHeap(osrm::engine::SearchEngineData::ManyToManyQueryHeap&, const osrm::engine::PhantomNode&) [with bool DIRECTION = false; osrm::engine::SearchEngineData::ManyToManyQueryHeap = osrm::util::BinaryHeap >]: phantom_node.IsValid() terminate called without an active exception ``` --- src/engine/plugins/table.cpp | 12 +++++++++++- unit_tests/library/table.cpp | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/engine/plugins/table.cpp b/src/engine/plugins/table.cpp index b5d391276..4448b98df 100644 --- a/src/engine/plugins/table.cpp +++ b/src/engine/plugins/table.cpp @@ -67,7 +67,17 @@ Status TablePlugin::HandleRequest(const datafacade::ContiguousInternalMemoryData return Error("TooBig", "Too many table coordinates", result); } - auto snapped_phantoms = SnapPhantomNodes(GetPhantomNodes(facade, params)); + auto phantom_nodes = GetPhantomNodes(facade, params); + + if (phantom_nodes.size() != params.coordinates.size()) + { + return Error("NoSegment", + std::string("Could not find a matching segment for coordinate ") + + std::to_string(phantom_nodes.size()), + result); + } + + auto snapped_phantoms = SnapPhantomNodes(phantom_nodes); auto result_table = algorithms.ManyToManySearch(snapped_phantoms, params.sources, params.destinations); diff --git a/unit_tests/library/table.cpp b/unit_tests/library/table.cpp index 2f0a04f5a..45ae643cd 100644 --- a/unit_tests/library/table.cpp +++ b/unit_tests/library/table.cpp @@ -151,4 +151,27 @@ BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix) } } +// See https://github.com/Project-OSRM/osrm-backend/pull/3992 +BOOST_AUTO_TEST_CASE(test_table_no_segment_for_some_coordinates) +{ + using namespace osrm; + + auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); + + TableParameters params; + params.coordinates.push_back(get_dummy_location()); + params.coordinates.push_back(get_dummy_location()); + // resembles query option: `&radiuses=0;` + params.radiuses.push_back(boost::make_optional(0.)); + params.radiuses.push_back(boost::none); + + json::Object result; + + const auto rc = osrm.Table(params, result); + + BOOST_CHECK(rc == Status::Error); + const auto code = result.values.at("code").get().value; + BOOST_CHECK_EQUAL(code, "NoSegment"); +} + BOOST_AUTO_TEST_SUITE_END()