Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#17: Handle integer overflows in ids #18

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Outdooractive/gis-tools",
"state" : {
"revision" : "271ffa105096a3c5889b211227c9a31dc59030db",
"version" : "1.2.0"
"revision" : "3a72a667c557e84527be32e5fa7ff34953716868",
"version" : "1.4.0"
}
},
{
Expand All @@ -23,26 +23,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "c8ed701b513cf5177118a175d85fbbbcd707ab41",
"version" : "1.3.0"
"revision" : "46989693916f56d1186bd59ac15124caef896560",
"version" : "1.3.1"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5",
"version" : "1.5.4"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf",
"state" : {
"revision" : "65e8f29b2d63c4e38e736b25c27b83e012159be8",
"version" : "1.25.2"
"revision" : "9f0c76544701845ad98716f3f6a774a892152bcb",
"version" : "1.26.0"
}
}
],
Expand Down
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ 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", 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.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.3"),
.package(url: "https://github.com/apple/swift-protobuf", from: "1.25.2"),
.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.26.0"),
],
targets: [
.executableTarget(
Expand Down
10 changes: 7 additions & 3 deletions Sources/MVTTools/VectorTileDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 2 additions & 4 deletions Sources/MVTTools/VectorTileEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions Tests/MVTToolsTests/TestData/bigint_id.geojson
Original file line number Diff line number Diff line change
@@ -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"
}
15 changes: 15 additions & 0 deletions Tests/MVTToolsTests/VectorTileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
Loading