From c20d7a97ddf97c654508932e2446dc991204bb8f Mon Sep 17 00:00:00 2001 From: Thomas Rasch Date: Wed, 28 Jun 2023 12:08:21 +0200 Subject: [PATCH] Check for invalid geometries in the WKT decoder --- Sources/GISTools/GeoJson/WKTCoder.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/GISTools/GeoJson/WKTCoder.swift b/Sources/GISTools/GeoJson/WKTCoder.swift index 8364e54..fbed1a5 100644 --- a/Sources/GISTools/GeoJson/WKTCoder.swift +++ b/Sources/GISTools/GeoJson/WKTCoder.swift @@ -488,6 +488,10 @@ extension WKTCoder { throw WKTCoderError.dataCorrupted } + guard x.isFinite, y.isFinite else { + throw WKTCoderError.invalidGeometry + } + var z: Double? var m: Double? @@ -502,6 +506,9 @@ extension WKTCoder { m = vector.get(at: 2) } + if z?.isFinite == false { z = nil } + if m?.isFinite == false { m = nil } + switch projection { case .epsg4326: coordinates.append(Coordinate3D(latitude: y, longitude: x, altitude: z, m: m))