From c3d23675d1f6d0df2788d52f0ee9cfb2454c2645 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Thu, 7 Sep 2017 13:48:09 -0700 Subject: [PATCH] Also fix arithmetic overflow when reading a Geobuf GeometryCollection --- geobuf.cpp | 3 +++ serial.cpp | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/geobuf.cpp b/geobuf.cpp index d83630fd..05ff8b66 100644 --- a/geobuf.cpp +++ b/geobuf.cpp @@ -255,6 +255,9 @@ std::vector readGeometry(protozero::pbf_reader &pbf, size_t dim, d dv.dv = readMultiLine(coords, lengths, dim, e, true); } else if (type == MULTIPOLYGON) { dv.dv = readMultiPolygon(coords, lengths, dim, e); + } else { + // GeometryCollection + return ret; } dv.type = type / 2 + 1; diff --git a/serial.cpp b/serial.cpp index 76b99d20..adb23bcc 100644 --- a/serial.cpp +++ b/serial.cpp @@ -425,7 +425,10 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) { if (sf.geometry.size() > 0 && (sf.bbox[2] < sf.bbox[0] || sf.bbox[3] < sf.bbox[1])) { fprintf(stderr, "Internal error: impossible feature bounding box %llx,%llx,%llx,%llx\n", sf.bbox[0], sf.bbox[1], sf.bbox[2], sf.bbox[3]); } - if (sf.bbox[2] - sf.bbox[0] > (2LL << (32 - sst->maxzoom)) || sf.bbox[3] - sf.bbox[1] > (2LL << (32 - sst->maxzoom))) { + if (sf.bbox[0] == LLONG_MAX) { + // No bounding box (empty geometry) + // Shouldn't happen, but avoid arithmetic overflow below + } else if (sf.bbox[2] - sf.bbox[0] > (2LL << (32 - sst->maxzoom)) || sf.bbox[3] - sf.bbox[1] > (2LL << (32 - sst->maxzoom))) { inline_meta = false; if (prevent[P_CLIPPING]) {