diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-03-15 22:24:31 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2019-03-16 10:10:02 +0100 |
| commit | ed2b26a09b407f7b580297d8a2cc516f786cbcc6 (patch) | |
| tree | 014721f64614c8420b402035fd62f8d9781d5f28 | |
| parent | 44fc7dda9fc411f7c2f052c2271d563bc52f2518 (diff) | |
| download | PROJ-ed2b26a09b407f7b580297d8a2cc516f786cbcc6.tar.gz PROJ-ed2b26a09b407f7b580297d8a2cc516f786cbcc6.zip | |
Hammer: avoid division by zero
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=12799
Credit to OSS Fuzz
| -rw-r--r-- | src/projections/hammer.cpp | 9 | ||||
| -rw-r--r-- | test/gie/builtins.gie | 8 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/projections/hammer.cpp b/src/projections/hammer.cpp index aa7d1ba9..b2e56a2c 100644 --- a/src/projections/hammer.cpp +++ b/src/projections/hammer.cpp @@ -24,7 +24,14 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque); double cosphi, d; - d = sqrt(2./(1. + (cosphi = cos(lp.phi)) * cos(lp.lam *= Q->w))); + cosphi = cos(lp.phi); + lp.lam *= Q->w; + double denom = 1. + cosphi * cos(lp.lam); + if( denom == 0.0 ) { + proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION); + return proj_coord_error().xy; + } + d = sqrt(2./denom); xy.x = Q->m * d * cosphi * sin(lp.lam); xy.y = Q->rm * d * sin(lp.phi); return xy; diff --git a/test/gie/builtins.gie b/test/gie/builtins.gie index c4f849a4..0c1a70b4 100644 --- a/test/gie/builtins.gie +++ b/test/gie/builtins.gie @@ -1855,7 +1855,7 @@ Hammer & Eckert-Greifendorff =============================================================================== ------------------------------------------------------------------------------- -operation +proj=hammer +a=6400000 +lat_1=0.5 +lat_2=2 +operation +proj=hammer +a=6400000 ------------------------------------------------------------------------------- tolerance 0.1 mm accept 2 1 @@ -1878,6 +1878,12 @@ accept -200 -100 expect -0.001790493 -0.000895247 +------------------------------------------------------------------------------- +operation +proj=hammer +a=6400000 +W=1 +------------------------------------------------------------------------------- +accept -180 0 +expect failure errno tolerance_condition + =============================================================================== Hatano Asymmetrical Equal Area PCyl, Sph. |
