Skip to content

Commit

Permalink
PJ_comill.c: avoid infinite loop in inverse method. Credit to OSS Fuzz
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jun 8, 2017
1 parent fa52fe3 commit 00ac8f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/PJ_comill.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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 */

Expand All @@ -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);
Expand All @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions src/pj_strerrno.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pj_err_list[] = {
"malformed pipeline", /* -50 */
"unit conversion factor must be > 0", /* -51 */
"invalid scale", /* -52 */
"non-convergent computation", /* -53 */
};

char *pj_strerrno(int err) {
Expand Down
1 change: 1 addition & 0 deletions src/projects.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ struct FACTORS {
#define PJD_ERR_GRID_AREA -48
#define PJD_ERR_CATALOG -49
#define PJD_ERR_INVALID_SCALE -52
#define PJD_ERR_NON_CONVERGENT -53

struct projFileAPI_t;

Expand Down

0 comments on commit 00ac8f3

Please sign in to comment.