diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-04-04 22:36:00 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2019-04-04 22:36:00 +0200 |
| commit | 70ed3efe60718be74d73d92ec2d121e2de268e53 (patch) | |
| tree | 2a16573f690d8f7e07df4dbbc0ab5fabd376723c | |
| parent | 1e2e512f9a671df504f6f01eee53dc26939b3c0a (diff) | |
| download | PROJ-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
| -rw-r--r-- | src/apps/gie.cpp | 2 | ||||
| -rw-r--r-- | src/ell_set.cpp | 24 | ||||
| -rw-r--r-- | src/init.cpp | 2 | ||||
| -rw-r--r-- | src/proj_internal.h | 2 | ||||
| -rw-r--r-- | src/projections/aea.cpp | 2 | ||||
| -rw-r--r-- | src/projections/lcc.cpp | 2 | ||||
| -rw-r--r-- | src/strerrno.cpp | 2 | ||||
| -rw-r--r-- | test/gie/builtins.gie | 4 | ||||
| -rw-r--r-- | test/gie/ellipsoid.gie | 16 |
9 files changed, 32 insertions, 24 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 */ diff --git a/test/gie/builtins.gie b/test/gie/builtins.gie index 4184d994..6976aaca 100644 --- a/test/gie/builtins.gie +++ b/test/gie/builtins.gie @@ -72,7 +72,7 @@ expect failure errno lat_larger_than_90 ------------------------------------------------------------------------------- operation +proj=aea +a=9999999 +b=.9 +lat_2=1 ------------------------------------------------------------------------- -expect failure errno eccentricity_is_one +expect failure errno invalid_eccentricity =============================================================================== Azimuthal Equidistant @@ -2703,7 +2703,7 @@ expect 1 2 ------------------------------------------------------------------------------- operation +proj=lcc +a=9999999 +b=.9 +lat_2=1 ------------------------------------------------------------------------- -expect failure errno eccentricity_is_one +expect failure errno invalid_eccentricity ------------------------------------------------------------------------------- operation +proj=lcc +ellps=GRS80 +lat_1=0 +lat_2=90 diff --git a/test/gie/ellipsoid.gie b/test/gie/ellipsoid.gie index 8099cfbd..b84a512f 100644 --- a/test/gie/ellipsoid.gie +++ b/test/gie/ellipsoid.gie @@ -44,7 +44,7 @@ tolerance 10 nm accept 1 2 expect 111319.4907932736 221194.0771604237 -accept 12 55 +accept 12 55s expect 1335833.8895192828 7326837.7148738774 ------------------------------------------------------------------------------- @@ -134,17 +134,23 @@ Shape parameters operation proj=utm zone=32 ellps=GRS80 rf=0 expect failure errno rev_flattening_is_zero +operation proj=utm zone=32 ellps=GRS80 e=-0.5 +expect failure errno invalid_eccentricity + +operation proj=utm zone=32 ellps=GRS80 e=1 +expect failure errno invalid_eccentricity + operation proj=utm zone=32 ellps=GRS80 es=1 -expect failure errno eccentricity_is_one +expect failure errno invalid_eccentricity operation proj=utm zone=32 a=1 es=1.1 -expect failure errno eccentricity_is_one +expect failure errno invalid_eccentricity operation proj=utm zone=32 ellps=GRS80 b=0 -expect failure errno eccentricity_is_one +expect failure errno invalid_eccentricity operation proj=utm zone=32 ellps=GRS80 f=1 -expect failure errno eccentricity_is_one +expect failure errno invalid_eccentricity operation proj=utm zone=32 ellps=GRS80 b=6000000 accept 12 55 |
