Skip to content

Commit 8fcfe7b

Browse files
authored
Merge pull request #1608 from joto/fix-large-relations
Again: ignore relations with more than 32k members
2 parents a55eacd + 1ab69d5 commit 8fcfe7b

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/osmdata.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ void osmdata_t::after_ways() { m_mid->after_ways(); }
8888

8989
void osmdata_t::relation(osmium::Relation const &rel)
9090
{
91+
if (rel.members().size() > 32767) {
92+
log_warn(
93+
"Relation id {} ignored, because it has more than 32767 members",
94+
rel.id());
95+
return;
96+
}
97+
9198
if (m_append && !rel.deleted()) {
9299
m_output->select_relation_members(rel.id());
93100
}
@@ -97,9 +104,6 @@ void osmdata_t::relation(osmium::Relation const &rel)
97104
if (rel.deleted()) {
98105
relation_delete(rel.id());
99106
} else {
100-
if (rel.members().size() > 32767) {
101-
return;
102-
}
103107
if (m_append) {
104108
relation_modify(rel);
105109
} else {

tests/regression.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import logging
2020
from os import path as op
21+
from io import StringIO
2122
import os
2223
import subprocess
2324
import sys
@@ -193,6 +194,27 @@ def run_import(cls, params, filename):
193194
raise RuntimeError("Import failed.")
194195

195196

197+
@classmethod
198+
def import_from_string(cls, content, format='opl'):
199+
cmdline = [CONFIG['executable']]
200+
params = cls.get_def_params() + cls.extra_params
201+
if not '-d' in params and not '--database' in params:
202+
cmdline.extend(('-d', CONFIG['test_database']))
203+
cmdline.extend(params)
204+
cmdline.extend(('-r', format, '-'))
205+
logging.info("Executing command: {}".format(' '.join(cmdline)))
206+
207+
proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE,
208+
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
209+
210+
(outp, err) = proc.communicate(input=content.encode('utf-8'))
211+
212+
if proc.returncode == 0:
213+
logging.debug(err.decode('utf-8'))
214+
else:
215+
logging.warning(err.decode('utf-8'))
216+
raise RuntimeError("Import failed.")
217+
196218
def assert_count(self, count, table, where=None):
197219
if self.schema:
198220
table = self.schema + '.' + table
@@ -873,3 +895,21 @@ class TestDBOutputSchema(BaseUpdateRunnerWithOutputSchema, unittest.TestCase,
873895
PgsqlBaseTests):
874896
extra_params = ['--slim', '--output-pgsql-schema=osm']
875897

898+
# Bad data tests
899+
900+
class TestBadOSMData(BaseRunner, unittest.TestCase):
901+
902+
extra_params = ['--slim']
903+
904+
def test_large_relation(self):
905+
content = StringIO()
906+
content.write('n1 x45 y34\n')
907+
content.write('r1 Ttype=multipolygon M')
908+
for _ in range(33000):
909+
content.write('n1@,')
910+
content.write('n1@')
911+
self.import_from_string(content.getvalue())
912+
913+
self.assert_count(1, 'planet_osm_nodes')
914+
self.assert_count(0, 'planet_osm_rels')
915+

0 commit comments

Comments
 (0)