aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--src/projections/lsat.cpp9
-rw-r--r--test/gie/builtins.gie8
2 files changed, 13 insertions, 4 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;
diff --git a/test/gie/builtins.gie b/test/gie/builtins.gie
index 5cbe6325..adaa98d9 100644
--- a/test/gie/builtins.gie
+++ b/test/gie/builtins.gie
@@ -2902,7 +2902,7 @@ Space oblique for LANDSAT
===============================================================================
-------------------------------------------------------------------------------
-operation +proj=lsat +ellps=GRS80 +lat_1=0.5 +lat_2=2 +lsat=1 +path=2
+operation +proj=lsat +ellps=GRS80 +lsat=1 +path=2
-------------------------------------------------------------------------------
tolerance 0.1 mm
accept 2 1
@@ -2924,6 +2924,12 @@ expect 126.000734469 -0.001880155
accept -200 -100
expect 126.002524373 -0.001723782
+-------------------------------------------------------------------------------
+operation +proj=lsat +path=1 +lsat=5 +ellps=sphere
+-------------------------------------------------------------------------------
+direction inverse
+accept 0 1e10
+expect failure errno invalid_x_or_y
===============================================================================
McBryde-Thomas Flat-Polar Sine (No. 1)