diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-04-18 22:19:59 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2019-04-18 22:19:59 +0200 |
| commit | 3f6c53ccee6062df95c595a0ea5b8cbed7e7f199 (patch) | |
| tree | caf537535841aee349580bb94a5b5f2fdf766351 /src/projections/nsper.cpp | |
| parent | 4c8a5cb8c7f69dd227f03f32eb99b53ea0586aba (diff) | |
| download | PROJ-3f6c53ccee6062df95c595a0ea5b8cbed7e7f199.tar.gz PROJ-3f6c53ccee6062df95c595a0ea5b8cbed7e7f199.zip | |
tpers: avoid division by zero
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=14342
Credit to OSS Fuzz
Diffstat (limited to 'src/projections/nsper.cpp')
| -rw-r--r-- | src/projections/nsper.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/projections/nsper.cpp b/src/projections/nsper.cpp index a0bb5686..37938924 100644 --- a/src/projections/nsper.cpp +++ b/src/projections/nsper.cpp @@ -96,7 +96,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0,0.0}; struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque); - double rh, cosz, sinz; + double rh; if (Q->tilt) { double bm, bq, yt; @@ -108,16 +108,18 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ xy.y = bq * Q->cg - bm * Q->sg; } rh = hypot(xy.x, xy.y); - if ((sinz = 1. - rh * rh * Q->pfact) < 0.) { - proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION); - return lp; - } - sinz = (Q->p - sqrt(sinz)) / (Q->pn1 / rh + rh / Q->pn1); - cosz = sqrt(1. - sinz * sinz); if (fabs(rh) <= EPS10) { lp.lam = 0.; lp.phi = P->phi0; } else { + double cosz, sinz; + sinz = 1. - rh * rh * Q->pfact; + if (sinz < 0.) { + proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION); + return lp; + } + sinz = (Q->p - sqrt(sinz)) / (Q->pn1 / rh + rh / Q->pn1); + cosz = sqrt(1. - sinz * sinz); switch (Q->mode) { case OBLIQ: lp.phi = asin(cosz * Q->sinph0 + xy.y * sinz * Q->cosph0 / rh); |
