aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-03-14 23:07:29 +0100
committerEven Rouault <even.rouault@spatialys.com>2019-03-14 23:07:29 +0100
commitfde6150b61aa225bb960d46f1611c82bf81315b3 (patch)
treeb7c2741163c58245a60242900111f59028667ae3 /src
parent5dc01e985e86b441ba2a671b712d3b211c8a2b33 (diff)
downloadPROJ-fde6150b61aa225bb960d46f1611c82bf81315b3.tar.gz
PROJ-fde6150b61aa225bb960d46f1611c82bf81315b3.zip
Reject eccentricity values larger than one
Valid eccentricity should be between 0 (included) or 1 (excluded) Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=13665 Credit to OSS Fuzz
Diffstat (limited to 'src')
-rw-r--r--src/ell_set.cpp20
-rw-r--r--src/init.cpp2
-rw-r--r--src/proj_internal.h2
-rw-r--r--src/strerrno.cpp2
4 files changed, 15 insertions, 11 deletions
diff --git a/src/ell_set.cpp b/src/ell_set.cpp
index 4c9fc892..71746895 100644
--- a/src/ell_set.cpp
+++ b/src/ell_set.cpp
@@ -280,8 +280,8 @@ static int ellps_shape (PJ *P) {
P->es = pj_atof (pj_param_value (par));
if (HUGE_VAL==P->es)
return proj_errno_set (P, PJD_ERR_INVALID_ARG);
- if (1==P->es)
- return proj_errno_set (P, PJD_ERR_ECCENTRICITY_IS_ONE);
+ if (P->es >= 1)
+ return proj_errno_set (P, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
break;
/* eccentricity, e */
@@ -291,8 +291,8 @@ static int ellps_shape (PJ *P) {
return proj_errno_set (P, PJD_ERR_INVALID_ARG);
if (0==P->e)
return proj_errno_set (P, PJD_ERR_INVALID_ARG);
- if (1==P->e)
- return proj_errno_set (P, PJD_ERR_ECCENTRICITY_IS_ONE);
+ if (P->e >= 1)
+ return proj_errno_set (P, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
P->es = P->e * P->e;
break;
@@ -301,8 +301,8 @@ static int ellps_shape (PJ *P) {
P->b = pj_atof (pj_param_value (par));
if (HUGE_VAL==P->b)
return proj_errno_set (P, PJD_ERR_INVALID_ARG);
- if (0==P->b)
- return proj_errno_set (P, PJD_ERR_ECCENTRICITY_IS_ONE);
+ if (P->b <= 0)
+ return proj_errno_set (P, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
if (P->b==P->a)
break;
P->f = (P->a - P->b) / P->a;
@@ -556,8 +556,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);
- return PJD_ERR_ECCENTRICITY_IS_ONE;
+ pj_ctx_set_errno( P->ctx, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
+ return PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER;
}
P->rone_es = 1./P->one_es;
@@ -712,6 +712,10 @@ bomb:
pj_ctx_set_errno(ctx, PJD_ERR_ES_LESS_THAN_ZERO);
return 1;
}
+ if (*es >= 1.) {
+ pj_ctx_set_errno(ctx, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
+ return 1;
+ }
if (*a <= 0.) {
pj_ctx_set_errno(ctx, PJD_ERR_MAJOR_AXIS_NOT_GIVEN);
return 1;
diff --git a/src/init.cpp b/src/init.cpp
index 2961bcca..13ea4ae8 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -680,7 +680,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);
+ return pj_default_destructor (PIN, PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER);
/* 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 448b65c8..cdde6bad 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 -6
+#define PJD_ERR_ECCENTRICITY_IS_ONE_OR_GREATER -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/strerrno.cpp b/src/strerrno.cpp
index 01097a42..5dedef98 100644
--- a/src/strerrno.cpp
+++ b/src/strerrno.cpp
@@ -14,7 +14,7 @@ pj_err_list[] = {
"no colon in init= string", /* -3 */
"projection not named", /* -4 */
"unknown projection id", /* -5 */
- "effective eccentricity = 1.", /* -6 */
+ "effective eccentricity >= 1.", /* -6 */
"unknown unit conversion id", /* -7 */
"invalid boolean param argument", /* -8 */
"unknown elliptical parameter name", /* -9 */