This repository was archived by the owner on Oct 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
This repository was archived by the owner on Oct 30, 2021. It is now read-only.
Overflow in pxy2zxy #75
Copy link
Copy link
Closed
Description
By running carmen-cache with -fsanitze=integer I see we only have one test that hits the if (zDist == 0) condition at
Line 934 in cd20c47
| if (zDist == 0) { |
It is the test/geocode-unit.proximity.test.js (specifically # forward province - multilayer) in carmen as of https://github.com/mapbox/carmen/commit/dbe167d609a6cc5374a20ddd7accb81ba62edf34.
Before the if (zDist == 0) condition the zMult variable overflows. This is harmless because it is not used, but it still ends up being 4294967295 because target_z and z are both 6 and so zDist because 0 at
Line 932 in cd20c47
| unsigned zDist = target_z - z; |
Tasks:
- Ensure we have test coverage in carmen-cache directly that triggers this condition (to protect from a regression if the
if (zDist == 0)condition were every accidentally removed - Fix the harmless overflow
Proposed fix:
diff --git a/src/binding.cpp b/src/binding.cpp
index b6bb856..a424111b 100644
--- a/src/binding.cpp
+++ b/src/binding.cpp
@@ -903,12 +903,12 @@ ZXY pxy2zxy(unsigned z, unsigned x, unsigned y, unsigned target_z) {
// Interval between parent and target zoom level
unsigned zDist = target_z - z;
- unsigned zMult = zDist - 1;
if (zDist == 0) {
zxy.x = x;
zxy.y = y;
return zxy;
}
+ unsigned zMult = zDist - 1;
// Midpoint length @ z for a tile at parent zoom level
unsigned pMid_d = static_cast<unsigned>(std::pow(2,zDist) / 2);Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels