|
5 | 5 |
|
6 | 6 | This file is part of Osmium (https://osmcode.org/libosmium).
|
7 | 7 |
|
8 |
| -Copyright 2013-2019 Jochen Topf <[email protected]> and others (see README). |
| 8 | +Copyright 2013-2020 Jochen Topf <[email protected]> and others (see README). |
9 | 9 |
|
10 | 10 | Boost Software License - Version 1.0 - August 17th, 2003
|
11 | 11 |
|
@@ -105,6 +105,12 @@ namespace osmium {
|
105 | 105 |
|
106 | 106 | static constexpr const std::size_t max_split_locations = 100ULL;
|
107 | 107 |
|
| 108 | + // Maximum recursion depth, stops complex multipolygons from |
| 109 | + // breaking everything. |
| 110 | + enum : unsigned { |
| 111 | + max_depth = 20U |
| 112 | + }; |
| 113 | + |
108 | 114 | struct slocation {
|
109 | 115 |
|
110 | 116 | enum {
|
@@ -713,7 +719,13 @@ namespace osmium {
|
713 | 719 |
|
714 | 720 | };
|
715 | 721 |
|
| 722 | + struct exceeded_max_depth {}; |
| 723 | + |
716 | 724 | void find_candidates(std::vector<candidate>& candidates, std::unordered_set<osmium::Location>& loc_done, const std::vector<location_to_ring_map>& xrings, const candidate& cand, unsigned depth = 0) {
|
| 725 | + if (depth > max_depth) { |
| 726 | + throw exceeded_max_depth{}; |
| 727 | + } |
| 728 | + |
717 | 729 | if (debug()) {
|
718 | 730 | std::cerr << " find_candidates sum=" << cand.sum << " start=" << cand.start_location << " stop=" << cand.stop_location << "\n";
|
719 | 731 | for (const auto& ring : cand.rings) {
|
@@ -826,7 +838,14 @@ namespace osmium {
|
826 | 838 | loc_done.insert(cand.stop_location);
|
827 | 839 |
|
828 | 840 | std::vector<candidate> candidates;
|
829 |
| - find_candidates(candidates, loc_done, xrings, cand); |
| 841 | + try { |
| 842 | + find_candidates(candidates, loc_done, xrings, cand); |
| 843 | + } catch (const exceeded_max_depth&) { |
| 844 | + if (m_config.debug_level > 0) { |
| 845 | + std::cerr << " Exceeded max depth (" << static_cast<unsigned>(max_depth) << ")\n"; |
| 846 | + } |
| 847 | + return false; |
| 848 | + } |
830 | 849 |
|
831 | 850 | if (candidates.empty()) {
|
832 | 851 | if (debug()) {
|
|
0 commit comments