summaryrefslogtreecommitdiff
path: root/deps
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-07-06 18:39:25 +0200
committerantirez <antirez@gmail.com>2015-07-06 18:39:25 +0200
commit5e04189887ed9100577374cede428c62d23fabe4 (patch)
tree977724fae62ccf1326d12bc79e55e546601a4807 /deps
parent5254c2d3c350f4edbb2f5dfde506fcb1ec58ee66 (diff)
downloadredis-5e04189887ed9100577374cede428c62d23fabe4.tar.gz
Geo: validate long,lat passed by user via API
Diffstat (limited to 'deps')
-rw-r--r--deps/geohash-int/geohash.c20
-rw-r--r--deps/geohash-int/geohash.h8
2 files changed, 19 insertions, 9 deletions
diff --git a/deps/geohash-int/geohash.c b/deps/geohash-int/geohash.c
index eaad9858d..5a0f3263d 100644
--- a/deps/geohash-int/geohash.c
+++ b/deps/geohash-int/geohash.c
@@ -112,19 +112,23 @@ static inline uint64_t deinterleave64(uint64_t interleaved) {
void geohashGetCoordRange(GeoHashRange *long_range, GeoHashRange *lat_range) {
/* These are constraints from EPSG:900913 / EPSG:3785 / OSGEO:41001 */
/* We can't geocode at the north/south pole. */
- long_range->max = 180.0;
- long_range->min = -180.0;
- lat_range->max = 85.05112878;
- lat_range->min = -85.05112878;
+ long_range->max = GEO_LONG_MAX;
+ long_range->min = GEO_LONG_MIN;
+ lat_range->max = GEO_LAT_MAX;
+ lat_range->min = GEO_LAT_MIN;
}
int geohashEncode(GeoHashRange *long_range, GeoHashRange *lat_range,
double longitude, double latitude, uint8_t step,
GeoHashBits *hash) {
- if (NULL == hash || step > 32 || step == 0 || RANGEPISZERO(lat_range) ||
- RANGEPISZERO(long_range)) {
- return 0;
- }
+ /* Check basic arguments sanity. */
+ if (hash == NULL || step > 32 || step == 0 ||
+ RANGEPISZERO(lat_range) || RANGEPISZERO(long_range)) return 0;
+
+ /* Return an error when trying to index outside the supported
+ * constraints. */
+ if (longitude > 180 || longitude < -180 ||
+ latitude > 85.05112878 || latitude < -85.05112878) return 0;
hash->bits = 0;
hash->step = step;
diff --git a/deps/geohash-int/geohash.h b/deps/geohash-int/geohash.h
index 5e76c249c..c2f57bed0 100644
--- a/deps/geohash-int/geohash.h
+++ b/deps/geohash-int/geohash.h
@@ -44,7 +44,13 @@ extern "C" {
#define RANGEISZERO(r) (!(r).max && !(r).min)
#define RANGEPISZERO(r) (r == NULL || RANGEISZERO(*r))
-#define GEO_STEP_MAX 26
+#define GEO_STEP_MAX 26 /* 26*2 = 52 bits. */
+
+/* Limits from EPSG:900913 / EPSG:3785 / OSGEO:41001 */
+#define GEO_LAT_MIN -85.05112878
+#define GEO_LAT_MAX 85.05112878
+#define GEO_LONG_MIN -180
+#define GEO_LONG_MAX 180
typedef enum {
GEOHASH_NORTH = 0,