aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-04-04 22:36:00 +0200
committerEven Rouault <even.rouault@spatialys.com>2019-04-04 22:36:00 +0200
commit70ed3efe60718be74d73d92ec2d121e2de268e53 (patch)
tree2a16573f690d8f7e07df4dbbc0ab5fabd376723c /src
parent1e2e512f9a671df504f6f01eee53dc26939b3c0a (diff)
downloadPROJ-70ed3efe60718be74d73d92ec2d121e2de268e53.tar.gz
PROJ-70ed3efe60718be74d73d92ec2d121e2de268e53.zip
Reject negative e parameter to avoid division by zero
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=14044 Credit to OSS Fuzz
Diffstat (limited to 'src')
-rw-r--r--src/apps/gie.cpp2
-rw-r--r--src/ell_set.cpp24
-rw-r--r--src/init.cpp2
-rw-r--r--src/proj_internal.h2
-rw-r--r--src/projections/aea.cpp2
-rw-r--r--src/projections/lcc.cpp2
-rw-r--r--src/strerrno.cpp2
7 files changed, 19 insertions, 17 deletions
diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp
index f0f7968f..5a86ebb7 100644
--- a/src/apps/gie.cpp
+++ b/src/apps/gie.cpp
@@ -1097,7 +1097,7 @@ static const struct errno_vs_err_const lookup[] = {
{"pjd_err_no_colon_in_init_string" , -3},
{"pjd_err_proj_not_named" , -4},
{"pjd_err_unknown_projection_id" , -5},
- {"pjd_err_eccentricity_is_one" , -6},
+ {"pjd_err_invalid_eccentricity" , -6},
{"pjd_err_unknown_unit_id" , -7},
{"pjd_err_invalid_boolean_param" , -8},
{"pjd_err_unknown_ellp_param" , -9},
diff --git a/src/ell_set.cpp b/src/ell_set.cpp
index c0b9016d..0d7fb6d5 100644
--- a/src/ell_set.cpp
+++ b/src/ell_set.cpp
@@ -280,7 +280,7 @@ static int ellps_shape (PJ *P) {
if (HUGE_VAL==P->es)
return proj_errno_set (P, PJD_ERR_INVALID_ARG);
if (P->es >= 1)
- return proj_errno_set (P, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
+ return proj_errno_set (P, PJD_ERR_INVALID_ECCENTRICITY);
break;
/* eccentricity, e */
@@ -288,10 +288,8 @@ static int ellps_shape (PJ *P) {
P->e = pj_atof (pj_param_value (par));
if (HUGE_VAL==P->e)
return proj_errno_set (P, PJD_ERR_INVALID_ARG);
- if (0==P->e)
- return proj_errno_set (P, PJD_ERR_INVALID_ARG);
- if (P->e >= 1)
- return proj_errno_set (P, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
+ if (P->e < 0 || P->e >= 1)
+ return proj_errno_set (P, PJD_ERR_INVALID_ECCENTRICITY);
P->es = P->e * P->e;
break;
@@ -301,7 +299,7 @@ static int ellps_shape (PJ *P) {
if (HUGE_VAL==P->b)
return proj_errno_set (P, PJD_ERR_INVALID_ARG);
if (P->b <= 0)
- return proj_errno_set (P, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
+ return proj_errno_set (P, PJD_ERR_INVALID_ECCENTRICITY);
if (P->b==P->a)
break;
P->f = (P->a - P->b) / P->a;
@@ -542,8 +540,8 @@ int pj_calc_ellipsoid_params (PJ *P, double a, double es) {
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;
+ pj_ctx_set_errno( P->ctx, PJD_ERR_INVALID_ECCENTRICITY);
+ return PJD_ERR_INVALID_ECCENTRICITY;
}
P->rf = P->f != 0.0 ? 1.0/P->f: HUGE_VAL;
@@ -563,8 +561,8 @@ int pj_calc_ellipsoid_params (PJ *P, double a, double es) {
P->one_es = 1. - P->es;
if (P->one_es == 0.) {
- pj_ctx_set_errno( P->ctx, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
- return PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER;
+ pj_ctx_set_errno( P->ctx, PJD_ERR_INVALID_ECCENTRICITY);
+ return PJD_ERR_INVALID_ECCENTRICITY;
}
P->rone_es = 1./P->one_es;
@@ -651,6 +649,10 @@ int pj_ell_set (projCtx ctx, paralist *pl, double *a, double *es) {
*es = pj_param(ctx,pl, "des").f;
else if (pj_param(ctx,pl, "te").i) { /* eccentricity */
e = pj_param(ctx,pl, "de").f;
+ if (e < 0) {
+ pj_ctx_set_errno(ctx, PJD_ERR_INVALID_ECCENTRICITY);
+ return 1;
+ }
*es = e * e;
} else if (pj_param(ctx,pl, "trf").i) { /* recip flattening */
*es = pj_param(ctx,pl, "drf").f;
@@ -720,7 +722,7 @@ bomb:
return 1;
}
if (*es >= 1.) {
- pj_ctx_set_errno(ctx, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
+ pj_ctx_set_errno(ctx, PJD_ERR_INVALID_ECCENTRICITY);
return 1;
}
if (*a <= 0.) {
diff --git a/src/init.cpp b/src/init.cpp
index cfcba96f..0fd303f5 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -679,7 +679,7 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
PIN->a_orig = PIN->a;
PIN->es_orig = PIN->es;
if (pj_calc_ellipsoid_params (PIN, PIN->a, PIN->es))
- return pj_default_destructor (PIN, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
+ return pj_default_destructor (PIN, PJD_ERR_INVALID_ECCENTRICITY);
/* Now that we have ellipse information check for WGS84 datum */
if( PIN->datum_type == PJD_3PARAM
diff --git a/src/proj_internal.h b/src/proj_internal.h
index 507bd329..66cadb1a 100644
--- a/src/proj_internal.h
+++ b/src/proj_internal.h
@@ -624,7 +624,7 @@ struct FACTORS {
#define PJD_ERR_NO_COLON_IN_INIT_STRING -3
#define PJD_ERR_PROJ_NOT_NAMED -4
#define PJD_ERR_UNKNOWN_PROJECTION_ID -5
-#define PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER -6
+#define PJD_ERR_INVALID_ECCENTRICITY -6
#define PJD_ERR_UNKNOWN_UNIT_ID -7
#define PJD_ERR_INVALID_BOOLEAN_PARAM -8
#define PJD_ERR_UNKNOWN_ELLP_PARAM -9
diff --git a/src/projections/aea.cpp b/src/projections/aea.cpp
index 8a80c49c..e488ddd9 100644
--- a/src/projections/aea.cpp
+++ b/src/projections/aea.cpp
@@ -182,7 +182,7 @@ static PJ *setup(PJ *P) {
Q->n = (m1 * m1 - m2 * m2) / (ml2 - ml1);
if (Q->n == 0) {
// Not quite, but es is very close to 1...
- return destructor(P, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
+ return destructor(P, PJD_ERR_INVALID_ECCENTRICITY);
}
}
Q->ec = 1. - .5 * P->one_es * log((1. - P->e) /
diff --git a/src/projections/lcc.cpp b/src/projections/lcc.cpp
index 55d28b80..3e93f98c 100644
--- a/src/projections/lcc.cpp
+++ b/src/projections/lcc.cpp
@@ -113,7 +113,7 @@ PJ *PROJECTION(lcc) {
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);
+ return pj_default_destructor(P, PJD_ERR_INVALID_ECCENTRICITY);
}
const double ml2 = pj_tsfn(Q->phi2, sinphi, P->e);
if( ml2 == 0 ) {
diff --git a/src/strerrno.cpp b/src/strerrno.cpp
index 4020cb23..c230d226 100644
--- a/src/strerrno.cpp
+++ b/src/strerrno.cpp
@@ -15,7 +15,7 @@ pj_err_list[] = {
"no colon in init= string", /* -3 */
"projection not named", /* -4 */
"unknown projection id", /* -5 */
- "effective eccentricity >= 1.", /* -6 */
+ "effective eccentricity < 0 or >= 1.", /* -6 */
"unknown unit conversion id", /* -7 */
"invalid boolean param argument", /* -8 */
"unknown elliptical parameter name", /* -9 */