From 08afe004aec8fe43613a7a869083a2fe950e3297 Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Thu, 19 Apr 2018 17:24:47 -0700 Subject: [PATCH] Fix tile with zoom level over 63 panics fixes #302 --- pkg/bing/bing_test.go | 8 ++++++++ pkg/bing/ext.go | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/bing/bing_test.go b/pkg/bing/bing_test.go index 002284fb..4f01790e 100644 --- a/pkg/bing/bing_test.go +++ b/pkg/bing/bing_test.go @@ -92,3 +92,11 @@ func TestLatLonClippingFuzz(t *testing.T) { } } } + +func TestIssue302(t *testing.T) { + // Requesting tile with zoom level > 63 crashes the server #302 + for z := uint64(0); z < 256; z++ { + tileX, tileY := PixelXYToTileXY(LatLongToPixelXY(33, -115, z)) + TileXYToBounds(tileX, tileY, z) + } +} diff --git a/pkg/bing/ext.go b/pkg/bing/ext.go index b9e73555..1ee06357 100644 --- a/pkg/bing/ext.go +++ b/pkg/bing/ext.go @@ -33,10 +33,10 @@ func TileXYToBounds(tileX, tileY int64, levelOfDetail uint64) (minLat, minLon, m maxLat, minLon = PixelXYToLatLong(pixelX, pixelY, levelOfDetail) pixelX, pixelY = TileXYToPixelXY(tileX+1, tileY+1) minLat, maxLon = PixelXYToLatLong(pixelX, pixelY, levelOfDetail) - if tileX%size == 0 { + if size == 0 || tileX%size == 0 { minLon = MinLongitude } - if tileX%size == size-1 { + if size == 0 || tileX%size == size-1 { maxLon = MaxLongitude } if tileY <= 0 {