aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-04-02 22:48:39 +0200
committerEven Rouault <even.rouault@spatialys.com>2019-04-02 22:48:39 +0200
commit20e67e474e5708b4d3a22cdf5a3ceb71ba627120 (patch)
treee999708c254011a0e96a52288dbf4fe2a9fc2f92
parent41fe4d06282f5a5374cd6d19382e0e37c2c277bc (diff)
downloadPROJ-20e67e474e5708b4d3a22cdf5a3ceb71ba627120.tar.gz
PROJ-20e67e474e5708b4d3a22cdf5a3ceb71ba627120.zip
Krovak: avoid divison by zero
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=14015 Credit to OSS Fuzz
-rw-r--r--src/projections/krovak.cpp16
-rw-r--r--test/gie/builtins.gie5
2 files changed, 18 insertions, 3 deletions
diff --git a/src/projections/krovak.cpp b/src/projections/krovak.cpp
index 591f8dcc..c30be411 100644
--- a/src/projections/krovak.cpp
+++ b/src/projections/krovak.cpp
@@ -115,7 +115,14 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forwar
deltav = -lp.lam * Q->alpha;
s = asin(cos(Q->ad) * sin(u) + sin(Q->ad) * cos(u) * cos(deltav));
- d = asin(cos(u) * sin(deltav) / cos(s));
+ const double cos_s = cos(s);
+ if( cos_s < 1e-12 )
+ {
+ xy.x = 0;
+ xy.y = 0;
+ return xy;
+ }
+ d = asin(cos(u) * sin(deltav) / cos_s);
eps = Q->n * d;
rho = Q->rho0 * pow(tan(S0 / 2. + M_PI_4) , Q->n) / pow(tan(s / 2. + M_PI_4) , Q->n);
@@ -148,7 +155,12 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, invers
eps = atan2(xy.y, xy.x);
d = eps / sin(S0);
- s = 2. * (atan( pow(Q->rho0 / rho, 1. / Q->n) * tan(S0 / 2. + M_PI_4)) - M_PI_4);
+ if( rho == 0.0 ) {
+ s = M_PI_2;
+ }
+ else {
+ s = 2. * (atan( pow(Q->rho0 / rho, 1. / Q->n) * tan(S0 / 2. + M_PI_4)) - M_PI_4);
+ }
u = asin(cos(Q->ad) * sin(s) - sin(Q->ad) * cos(s) * cos(d));
deltav = asin(cos(s) * sin(d) / cos(u));
diff --git a/test/gie/builtins.gie b/test/gie/builtins.gie
index 5f78c979..094156ac 100644
--- a/test/gie/builtins.gie
+++ b/test/gie/builtins.gie
@@ -2239,6 +2239,8 @@ accept -2 1
expect -3756305.328869175 -6478142.561571511
accept -2 -1
expect -3831703.658501982 -6759107.170155395
+accept 24.833333333333 59.757598563058
+expect 0 0
direction inverse
accept 200 100
@@ -2249,7 +2251,8 @@ accept -200 100
expect 24.830447748 59.758403933
accept -200 -100
expect 24.830351182 59.756888426
-
+accept 0 0
+expect 24.833333333333 59.757598563058
===============================================================================
Laborde