aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-03-24 17:11:55 +0100
committerEven Rouault <even.rouault@spatialys.com>2019-03-24 17:11:55 +0100
commitf41da8f8e0f6f41ca522279274da1f2441828eda (patch)
tree8d13b1fb5aec779338fc651dcb093e80cd244c16
parent0529b07f81d3c027e101c6e1eddb4685e957934d (diff)
downloadPROJ-f41da8f8e0f6f41ca522279274da1f2441828eda.tar.gz
PROJ-f41da8f8e0f6f41ca522279274da1f2441828eda.zip
vandg inverse: avoid division by zero
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=13894 Credit to OSS Fuzz
-rw-r--r--src/projections/vandg.cpp9
-rw-r--r--test/gie/builtins.gie7
2 files changed, 15 insertions, 1 deletions
diff --git a/src/projections/vandg.cpp b/src/projections/vandg.cpp
index 89620356..c669f8fa 100644
--- a/src/projections/vandg.cpp
+++ b/src/projections/vandg.cpp
@@ -80,7 +80,14 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
al = c1 / c3 - THIRD * c2 * c2;
m = 2. * sqrt(-THIRD * al);
d = C2_27 * c2 * c2 * c2 + (c0 * c0 - THIRD * c2 * c1) / c3;
- if (((t = fabs(d = 3. * d / (al * m))) - TOL) <= 1.) {
+ const double al_mul_m = al * m;
+ if( al_mul_m == 0 ) {
+ proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
+ return proj_coord_error().lp;
+ }
+ d = 3. * d /al_mul_m;
+ t = fabs(d);
+ if ((t - TOL) <= 1.) {
d = t > 1. ? (d > 0. ? 0. : M_PI) : acos(d);
lp.phi = M_PI * (m * cos(d * THIRD + PI4_3) - THIRD * c2);
if (xy.y < 0.) lp.phi = -lp.phi;
diff --git a/test/gie/builtins.gie b/test/gie/builtins.gie
index f0290fa2..46375706 100644
--- a/test/gie/builtins.gie
+++ b/test/gie/builtins.gie
@@ -5388,6 +5388,13 @@ expect -0.001790494 0.000895247
accept -200 -100
expect -0.001790494 -0.000895247
+-------------------------------------------------------------------------------
+operation +proj=vandg +R=1
+-------------------------------------------------------------------------------
+direction inverse
+accept 0 -1e100
+expect failure errno tolerance_condition
+
===============================================================================
van der Grinten II