aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2019-03-21 08:27:37 +0100
committerGitHub <noreply@github.com>2019-03-21 08:27:37 +0100
commitdc1f9d8ba25d3fd35ef767e18903ac9dad91e7e3 (patch)
tree41442c2b864d89aaf2b308d1f09735cd6461e5d6 /src
parent9ead1bfe5afd7e519fe5f83b6603e5147fa91411 (diff)
parent17f2f7cf8bcaa5a4edc9e94d2bd6d8e633455c03 (diff)
downloadPROJ-dc1f9d8ba25d3fd35ef767e18903ac9dad91e7e3.tar.gz
PROJ-dc1f9d8ba25d3fd35ef767e18903ac9dad91e7e3.zip
Merge pull request #1335 from rouault/fix_ossfuzz_13790
Fix ossfuzz 13790 + tweak CI regarding backport branches
Diffstat (limited to 'src')
-rw-r--r--src/ell_set.cpp4
-rw-r--r--src/projections/imw_p.cpp10
-rw-r--r--src/projections/isea.cpp24
-rw-r--r--src/projections/laea.cpp3
-rw-r--r--src/projections/lcc.cpp4
-rw-r--r--src/projections/ob_tran.cpp16
-rw-r--r--src/projections/sterea.cpp7
7 files changed, 57 insertions, 11 deletions
diff --git a/src/ell_set.cpp b/src/ell_set.cpp
index 386b4f46..d0714bee 100644
--- a/src/ell_set.cpp
+++ b/src/ell_set.cpp
@@ -542,6 +542,10 @@ int pj_calc_ellipsoid_params (PJ *P, double a, double es) {
/* flattening */
if (0==P->f)
P->f = 1 - cos (P->alpha); /* = 1 - sqrt (1 - PIN->es); */
+ if (P->f == 1.0) {
+ pj_ctx_set_errno( P->ctx, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
+ return PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER;
+ }
P->rf = P->f != 0.0 ? 1.0/P->f: HUGE_VAL;
/* second flattening */
diff --git a/src/projections/imw_p.cpp b/src/projections/imw_p.cpp
index 723fcc48..41882df2 100644
--- a/src/projections/imw_p.cpp
+++ b/src/projections/imw_p.cpp
@@ -116,7 +116,12 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
lp.lam = xy.x / cos(lp.phi);
do {
t = loc_for(lp, P, &yc);
- lp.phi = ((lp.phi - Q->phi_1) * (xy.y - yc) / (t.y - yc)) + Q->phi_1;
+ const double denom = t.y - yc;
+ if( denom == 0 ) {
+ proj_errno_set(P, PJD_ERR_NON_CONVERGENT);
+ return proj_coord_error().lp;
+ }
+ lp.phi = ((lp.phi - Q->phi_1) * (xy.y - yc) / denom) + Q->phi_1;
lp.lam = lp.lam * xy.x / t.x;
i ++;
} while (i < N_MAX_ITER &&
@@ -124,7 +129,8 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
if( i == N_MAX_ITER )
{
- lp.lam = lp.phi = HUGE_VAL;
+ proj_errno_set(P, PJD_ERR_NON_CONVERGENT);
+ return proj_coord_error().lp;
}
return lp;
diff --git a/src/projections/isea.cpp b/src/projections/isea.cpp
index fc74bebe..659ca790 100644
--- a/src/projections/isea.cpp
+++ b/src/projections/isea.cpp
@@ -10,6 +10,8 @@
#include <stdlib.h>
#include <string.h>
+#include <limits>
+
#define PJ_LIB__
#include "proj_internal.h"
#include "proj_math.h"
@@ -89,6 +91,9 @@ static void hexbin2(double width, double x, double y, long *i, long *j) {
y = y - x / 2.0; /* adjustment for rotated X */
/* adjust for actual hexwidth */
+ if( width == 0 ) {
+ throw "Division by zero";
+ }
x /= width;
y /= width;
@@ -100,6 +105,9 @@ static void hexbin2(double width, double x, double y, long *i, long *j) {
iy = lround(ry);
rz = floor(z + 0.5);
iz = lround(rz);
+ if( fabs(rx + ry + rz) > std::numeric_limits<int>::max() ) {
+ throw "Integer overflow";
+ }
s = ix + iy + iz;
@@ -764,11 +772,18 @@ static int isea_dddi(struct isea_dgg *g, int quad, struct isea_pt *pt,
}
/* todo might want to do this as an iterated loop */
if (g->aperture >0) {
- sidelength = lround(pow(g->aperture, g->resolution / 2.0));
+ double sidelengthDouble = pow(g->aperture, g->resolution / 2.0);
+ if( fabs(sidelengthDouble) > std::numeric_limits<int>::max() ) {
+ throw "Integer overflow";
+ }
+ sidelength = lround(sidelengthDouble);
} else {
sidelength = g->resolution;
}
+ if( sidelength == 0 ) {
+ throw "Division by zero";
+ }
hexwidth = 1.0 / sidelength;
v = *pt;
@@ -1004,7 +1019,12 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
in.lon = lp.lam;
in.lat = lp.phi;
- out = isea_forward(&Q->dgg, &in);
+ try {
+ out = isea_forward(&Q->dgg, &in);
+ } catch( const char* ) {
+ proj_errno_set(P, PJD_ERR_NON_CONVERGENT);
+ return proj_coord_error().xy;
+ }
xy.x = out.x;
xy.y = out.y;
diff --git a/src/projections/laea.cpp b/src/projections/laea.cpp
index 22fb1691..11b89a96 100644
--- a/src/projections/laea.cpp
+++ b/src/projections/laea.cpp
@@ -248,6 +248,9 @@ PJ *PROJECTION(laea) {
P->destructor = destructor;
t = fabs(P->phi0);
+ if (t > M_HALFPI + EPS10 ) {
+ return destructor(P, PJD_ERR_LAT_LARGER_THAN_90);
+ }
if (fabs(t - M_HALFPI) < EPS10)
Q->mode = P->phi0 < 0. ? S_POLE : N_POLE;
else if (fabs(t) < EPS10)
diff --git a/src/projections/lcc.cpp b/src/projections/lcc.cpp
index a1fe79a9..5eee0d14 100644
--- a/src/projections/lcc.cpp
+++ b/src/projections/lcc.cpp
@@ -108,6 +108,10 @@ PJ *PROJECTION(lcc) {
if (secant) { /* secant cone */
sinphi = sin(Q->phi2);
Q->n = log(m1 / pj_msfn(sinphi, cos(Q->phi2), P->es));
+ if (Q->n == 0) {
+ // Not quite, but es is very close to 1...
+ return pj_default_destructor(P, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
+ }
Q->n /= log(ml1 / pj_tsfn(Q->phi2, sinphi, P->e));
}
Q->c = (Q->rho0 = m1 * pow(ml1, -Q->n) / Q->n);
diff --git a/src/projections/ob_tran.cpp b/src/projections/ob_tran.cpp
index 6daae394..f9eaa6f0 100644
--- a/src/projections/ob_tran.cpp
+++ b/src/projections/ob_tran.cpp
@@ -154,6 +154,11 @@ static ARGS ob_tran_target_params (paralist *params) {
if (0!=strncmp (args.argv[i], "o_proj=", 7))
continue;
args.argv[i] += 2;
+ if (strcmp(args.argv[i], "proj=ob_tran") == 0 ) {
+ pj_dealloc (args.argv);
+ args.argc = 0;
+ args.argv = nullptr;
+ }
break;
}
@@ -164,7 +169,6 @@ static ARGS ob_tran_target_params (paralist *params) {
PJ *PROJECTION(ob_tran) {
double phip;
- char *name;
ARGS args;
PJ *R; /* projection to rotate */
@@ -176,15 +180,15 @@ PJ *PROJECTION(ob_tran) {
P->destructor = destructor;
/* get name of projection to be translated */
- if (!(name = pj_param(P->ctx, P->params, "so_proj").s))
+ if (pj_param(P->ctx, P->params, "so_proj").s == nullptr)
return destructor(P, PJD_ERR_NO_ROTATION_PROJ);
- /* avoid endless recursion */
- if( strcmp(name, "ob_tran") == 0 )
- return destructor(P, PJD_ERR_FAILED_TO_FIND_PROJ);
-
/* Create the target projection object to rotate */
args = ob_tran_target_params (P->params);
+ /* avoid endless recursion */
+ if (args.argv == nullptr ) {
+ return destructor(P, PJD_ERR_FAILED_TO_FIND_PROJ);
+ }
R = pj_init_ctx (pj_get_ctx(P), args.argc, args.argv);
pj_dealloc (args.argv);
diff --git a/src/projections/sterea.cpp b/src/projections/sterea.cpp
index b6ebc7b4..964bb588 100644
--- a/src/projections/sterea.cpp
+++ b/src/projections/sterea.cpp
@@ -53,7 +53,12 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
sinc = sin(lp.phi);
cosc = cos(lp.phi);
cosl = cos(lp.lam);
- k = P->k0 * Q->R2 / (1. + Q->sinc0 * sinc + Q->cosc0 * cosc * cosl);
+ const double denom = 1. + Q->sinc0 * sinc + Q->cosc0 * cosc * cosl;
+ if( denom == 0.0 ) {
+ proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
+ return proj_coord_error().xy;
+ }
+ k = P->k0 * Q->R2 / denom;
xy.x = k * cosc * sin(lp.lam);
xy.y = k * (Q->cosc0 * sinc - Q->sinc0 * cosc * cosl);
return xy;