aboutsummaryrefslogtreecommitdiff
path: root/src/projections/lsat.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-04-10 23:55:52 +0200
committerEven Rouault <even.rouault@spatialys.com>2019-04-10 23:55:52 +0200
commit685ad56156f320760c92f7f71fa4acbf3e00acc9 (patch)
tree0c9310b5a781e704e20f6754076c51a6d4ec7a47 /src/projections/lsat.cpp
parentfb125618fd18f112ed6f37662b021d07a602ff90 (diff)
downloadPROJ-685ad56156f320760c92f7f71fa4acbf3e00acc9.tar.gz
PROJ-685ad56156f320760c92f7f71fa4acbf3e00acc9.zip
lsat: avoid division by zero in inverse
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=14135 Credit to OSS Fuzz
Diffstat (limited to 'src/projections/lsat.cpp')
-rw-r--r--src/projections/lsat.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/projections/lsat.cpp b/src/projections/lsat.cpp
index 5b7520d3..f9eec1b9 100644
--- a/src/projections/lsat.cpp
+++ b/src/projections/lsat.cpp
@@ -112,7 +112,6 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int nn;
double lamt, sdsq, s, lamdp, phidp, sppsq, dd, sd, sl, fac, scl, sav, spp;
-
lamdp = xy.x / Q->b;
nn = 50;
do {
@@ -135,10 +134,14 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
lamdp -= TOL;
spp = sin(phidp);
sppsq = spp * spp;
+ const double denom = 1. - sppsq * (1. + Q->u);
+ if( denom == 0.0 ) {
+ proj_errno_set(P, PJD_ERR_INVALID_X_OR_Y);
+ return proj_coord_error().lp;
+ }
lamt = atan(((1. - sppsq * P->rone_es) * tan(lamdp) *
Q->ca - spp * Q->sa * sqrt((1. + Q->q * dd) * (
- 1. - sppsq) - sppsq * Q->u) / cos(lamdp)) / (1. - sppsq
- * (1. + Q->u)));
+ 1. - sppsq) - sppsq * Q->u) / cos(lamdp)) / denom);
sl = lamt >= 0. ? 1. : -1.;
scl = cos(lamdp) >= 0. ? 1. : -1;
lamt -= M_HALFPI * (1. - scl) * sl;