diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2017-06-08 14:54:29 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2017-06-08 14:54:29 +0200 |
| commit | 00ac8f3a9c129a7189df6bf2a6606ffbfd5c8ea3 (patch) | |
| tree | 002ca97ae127d69063cfe0bb5dd16c42369a2f35 /src/PJ_comill.c | |
| parent | fa52fe3cef2cb435db08f09a084b8b9611e4392a (diff) | |
| download | PROJ-00ac8f3a9c129a7189df6bf2a6606ffbfd5c8ea3.tar.gz PROJ-00ac8f3a9c129a7189df6bf2a6606ffbfd5c8ea3.zip | |
PJ_comill.c: avoid infinite loop in inverse method. Credit to OSS Fuzz
Diffstat (limited to 'src/PJ_comill.c')
| -rw-r--r-- | src/PJ_comill.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/PJ_comill.c b/src/PJ_comill.c index c492dc95..1a4508b1 100644 --- a/src/PJ_comill.c +++ b/src/PJ_comill.c @@ -19,7 +19,8 @@ PROJ_HEAD(comill, "Compact Miller") "\n\tCyl., Sph."; #define C3 (5 * K3) #define EPS 1e-11 #define MAX_Y (0.6000207669862655 * M_PI) - +/* Not sure at all of the appropriate number for MAX_ITER... */ +#define MAX_ITER 100 static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */ XY xy = {0.0,0.0}; @@ -37,6 +38,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */ LP lp = {0.0,0.0}; double yc, tol, y2, f, fder; + int i; (void) P; /* silence unused parameter warnings */ @@ -49,7 +51,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */ /* latitude */ yc = xy.y; - for (;;) { /* Newton-Raphson */ + for (i = MAX_ITER; i ; --i) { /* Newton-Raphson */ y2 = yc * yc; f = (yc * (K1 + y2 * (K2 + K3 * y2))) - xy.y; fder = C1 + y2 * (C2 + C3 * y2); @@ -58,6 +60,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */ break; } } + if( i == 0 ) + pj_ctx_set_errno( P->ctx, PJD_ERR_NON_CONVERGENT ); lp.phi = yc; /* longitude */ |
