From 33c00cd704911e4645a6246e9717848c627aa297 Mon Sep 17 00:00:00 2001 From: Thomas Rasch Date: Tue, 19 Mar 2024 11:55:26 +0100 Subject: [PATCH 1/3] #17: Handle integer overflows in ids --- Package.resolved | 12 ++++++------ Package.swift | 6 +++--- Sources/MVTTools/VectorTileDecoder.swift | 10 +++++++--- Sources/MVTTools/VectorTileEncoder.swift | 6 ++---- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Package.resolved b/Package.resolved index c1c63cf..83279f2 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Outdooractive/gis-tools", "state" : { - "revision" : "271ffa105096a3c5889b211227c9a31dc59030db", - "version" : "1.2.0" + "branch" : "45_feature_id_overflow", + "revision" : "4e74243416460049a927008a0e515001f3132566" } }, { @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-argument-parser", "state" : { - "revision" : "c8ed701b513cf5177118a175d85fbbbcd707ab41", - "version" : "1.3.0" + "revision" : "46989693916f56d1186bd59ac15124caef896560", + "version" : "1.3.1" } }, { @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-log.git", "state" : { - "revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed", - "version" : "1.5.3" + "revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5", + "version" : "1.5.4" } }, { diff --git a/Package.swift b/Package.swift index bf12246..b9f079a 100644 --- a/Package.swift +++ b/Package.swift @@ -19,10 +19,10 @@ let package = Package( targets: ["MVTTools"]), ], dependencies: [ - .package(url: "https://github.com/Outdooractive/gis-tools", from: "1.2.0"), + .package(url: "https://github.com/Outdooractive/gis-tools", branch: "45_feature_id_overflow"), .package(url: "https://github.com/1024jp/GzipSwift.git", from: "5.2.0"), - .package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"), - .package(url: "https://github.com/apple/swift-log.git", from: "1.5.3"), + .package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.1"), + .package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"), .package(url: "https://github.com/apple/swift-protobuf", from: "1.25.2"), ], targets: [ diff --git a/Sources/MVTTools/VectorTileDecoder.swift b/Sources/MVTTools/VectorTileDecoder.swift index 708e8c9..24307cd 100644 --- a/Sources/MVTTools/VectorTileDecoder.swift +++ b/Sources/MVTTools/VectorTileDecoder.swift @@ -146,9 +146,13 @@ extension VectorTile { properties[key] = value } layerFeature.properties = properties - layerFeature.id = feature.hasID - ? .int(Int(feature.id)) - : .string(UUID().uuidString) + + if feature.hasID { + layerFeature.id = Feature.Identifier(value: feature.id) + } + else { + layerFeature.id = .string(UUID().uuidString) + } layerFeatures.append(layerFeature) } diff --git a/Sources/MVTTools/VectorTileEncoder.swift b/Sources/MVTTools/VectorTileEncoder.swift index 3b5eca5..d9997c0 100644 --- a/Sources/MVTTools/VectorTileEncoder.swift +++ b/Sources/MVTTools/VectorTileEncoder.swift @@ -273,10 +273,8 @@ extension VectorTile { vectorTileFeature.type = geometryType vectorTileFeature.geometry = geometryIntegers - if case let .int(int) = feature.id, - let converted = UInt64(exactly: int) - { - vectorTileFeature.id = converted + if let featureId = feature.id?.uint64Value { + vectorTileFeature.id = featureId } return vectorTileFeature From 29e7a1b69ad038f844b6b192913080727742efdb Mon Sep 17 00:00:00 2001 From: Thomas Rasch Date: Tue, 19 Mar 2024 16:22:22 +0100 Subject: [PATCH 2/3] Test case with a big int --- Package.resolved | 2 +- .../MVTToolsTests/TestData/bigint_id.geojson | 37 +++++++++++++++++++ Tests/MVTToolsTests/VectorTileTests.swift | 15 ++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 Tests/MVTToolsTests/TestData/bigint_id.geojson diff --git a/Package.resolved b/Package.resolved index 83279f2..1d132d2 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,7 +6,7 @@ "location" : "https://github.com/Outdooractive/gis-tools", "state" : { "branch" : "45_feature_id_overflow", - "revision" : "4e74243416460049a927008a0e515001f3132566" + "revision" : "1cb8776f353dfd0b938251b1eb12ec6ddbb5f44c" } }, { diff --git a/Tests/MVTToolsTests/TestData/bigint_id.geojson b/Tests/MVTToolsTests/TestData/bigint_id.geojson new file mode 100644 index 0000000..a82ebc4 --- /dev/null +++ b/Tests/MVTToolsTests/TestData/bigint_id.geojson @@ -0,0 +1,37 @@ +{ + "bbox" : [ + -120.37960052490236, + 34.045263375550654, + -120.37960052490236, + 34.045263375550654 + ], + "geometry" : { + "coordinates" : [ + -120.37960052490236, + 34.045263375550654 + ], + "type" : "Point" + }, + "id" : 18446744073638380036, + "properties" : { + "class" : "island", + "name" : "San Miguel Island", + "name_de" : "San Miguel Island", + "name_en" : "San Miguel Island", + "name_int" : "San Miguel Island", + "name:ca" : "illa San Miguel", + "name:de" : "San Miguel Island", + "name:en" : "San Miguel Island", + "name:es" : "Isla San Miguel", + "name:et" : "San Migueli saar", + "name:fr" : "île San Miguel", + "name:it" : "Isola di San Miguel", + "name:ja" : "サンミゲル島 (チャンネル諸島)", + "name:latin" : "San Miguel Island", + "name:nl" : "San Miguel Island", + "name:pl" : "San Miguel Island", + "name:zh" : "聖米格爾島", + "rank" : 3 + }, + "type" : "Feature" +} diff --git a/Tests/MVTToolsTests/VectorTileTests.swift b/Tests/MVTToolsTests/VectorTileTests.swift index 0f1d19f..e4a589b 100644 --- a/Tests/MVTToolsTests/VectorTileTests.swift +++ b/Tests/MVTToolsTests/VectorTileTests.swift @@ -111,4 +111,19 @@ final class VectorTileTests: XCTestCase { XCTAssertEqual(tile1.features(for: "test2")!.count, 1) } + func testEncodeDecodeBigInt() throws { + let feature = try XCTUnwrap(Feature(jsonData: TestData.dataFromFile(name: "bigint_id.geojson"))) + XCTAssertEqual(feature.id, .uint(18446744073638380036)) + + var tile = try XCTUnwrap(VectorTile(x: 10, y: 25, z: 6)) + tile.setFeatures([feature], for: "test") + let tileData = try XCTUnwrap(tile.data()) + XCTAssertFalse(tileData.isEmpty) + + let tile2 = try XCTUnwrap(VectorTile(data: tileData, x: 10, y: 25, z: 6)) + let feature2: Feature = try XCTUnwrap(tile2.features(for: "test")?.first) + + XCTAssertEqual(feature.id, feature2.id) + } + } From f9b3584dfb5f1fb26d3233c2ce5f672ce9f46352 Mon Sep 17 00:00:00 2001 From: Thomas Rasch Date: Mon, 8 Apr 2024 13:42:30 +0200 Subject: [PATCH 3/3] Dependency updates --- Package.resolved | 8 ++++---- Package.swift | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Package.resolved b/Package.resolved index 1d132d2..f7fd02f 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Outdooractive/gis-tools", "state" : { - "branch" : "45_feature_id_overflow", - "revision" : "1cb8776f353dfd0b938251b1eb12ec6ddbb5f44c" + "revision" : "3a72a667c557e84527be32e5fa7ff34953716868", + "version" : "1.4.0" } }, { @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-protobuf", "state" : { - "revision" : "65e8f29b2d63c4e38e736b25c27b83e012159be8", - "version" : "1.25.2" + "revision" : "9f0c76544701845ad98716f3f6a774a892152bcb", + "version" : "1.26.0" } } ], diff --git a/Package.swift b/Package.swift index b9f079a..bca7682 100644 --- a/Package.swift +++ b/Package.swift @@ -19,11 +19,11 @@ let package = Package( targets: ["MVTTools"]), ], dependencies: [ - .package(url: "https://github.com/Outdooractive/gis-tools", branch: "45_feature_id_overflow"), + .package(url: "https://github.com/Outdooractive/gis-tools", from: "1.4.0"), .package(url: "https://github.com/1024jp/GzipSwift.git", from: "5.2.0"), .package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.1"), .package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"), - .package(url: "https://github.com/apple/swift-protobuf", from: "1.25.2"), + .package(url: "https://github.com/apple/swift-protobuf", from: "1.26.0"), ], targets: [ .executableTarget(