diff options
| author | Even Rouault <even.rouault@mines-paris.org> | 2019-04-05 15:41:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-05 15:41:28 +0200 |
| commit | 0ea2b4e82700ba9aa0ae67ec0ee72ae58bc4f0c9 (patch) | |
| tree | a602774d5e52071f006b37d59147708a4b57739e | |
| parent | 1e2e512f9a671df504f6f01eee53dc26939b3c0a (diff) | |
| parent | f6ba932a8f1d7f0775d4ebe367b2d5faef57461a (diff) | |
| download | PROJ-0ea2b4e82700ba9aa0ae67ec0ee72ae58bc4f0c9.tar.gz PROJ-0ea2b4e82700ba9aa0ae67ec0ee72ae58bc4f0c9.zip | |
Merge pull request #1411 from rouault/ossfuzz_14044_and_all
Ossfuzz 14044 and others
| -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/iso19111/io.cpp | 3 | ||||
| -rw-r--r-- | src/proj_internal.h | 2 | ||||
| -rw-r--r-- | src/projections/aea.cpp | 2 | ||||
| -rw-r--r-- | src/projections/imw_p.cpp | 14 | ||||
| -rw-r--r-- | src/projections/krovak.cpp | 6 | ||||
| -rw-r--r-- | src/projections/lcc.cpp | 5 | ||||
| -rw-r--r-- | src/strerrno.cpp | 2 | ||||
| -rw-r--r-- | test/gie/builtins.gie | 38 | ||||
| -rw-r--r-- | test/gie/ellipsoid.gie | 16 | ||||
| -rw-r--r-- | test/unit/test_io.cpp | 3 | ||||
| -rw-r--r-- | test/unit/test_operation.cpp | 6 |
14 files changed, 92 insertions, 33 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/iso19111/io.cpp b/src/iso19111/io.cpp index 51fda1c1..360d55a2 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -6091,6 +6091,9 @@ static UnitOfMeasure _buildUnit(const LinearUnitDesc *unitsMatch) { static UnitOfMeasure _buildUnit(double to_meter_value) { // TODO: look-up in EPSG catalog + if (to_meter_value == 0) { + throw ParsingException("invalid unit value"); + } return UnitOfMeasure("unknown", to_meter_value, UnitOfMeasure::Type::LINEAR); } 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/imw_p.cpp b/src/projections/imw_p.cpp index 41882df2..8d675318 100644 --- a/src/projections/imw_p.cpp +++ b/src/projections/imw_p.cpp @@ -117,12 +117,16 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ do { t = loc_for(lp, P, &yc); const double denom = t.y - yc; - if( denom == 0 ) { - proj_errno_set(P, PJD_ERR_NON_CONVERGENT); - return proj_coord_error().lp; + if( denom != 0 || fabs(t.y - xy.y) > TOL ) + { + 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.phi = ((lp.phi - Q->phi_1) * (xy.y - yc) / denom) + Q->phi_1; - lp.lam = lp.lam * xy.x / t.x; + if( t.x != 0 || fabs(t.x - xy.x) > TOL ) + lp.lam = lp.lam * xy.x / t.x; i ++; } while (i < N_MAX_ITER && (fabs(t.x - xy.x) > TOL || fabs(t.y - xy.y) > TOL)); diff --git a/src/projections/krovak.cpp b/src/projections/krovak.cpp index c30be411..c3f61f3d 100644 --- a/src/projections/krovak.cpp +++ b/src/projections/krovak.cpp @@ -222,7 +222,11 @@ PJ *PROJECTION(krovak) { Q->alpha = sqrt(1. + (P->es * pow(cos(P->phi0), 4)) / (1. - P->es)); u0 = asin(sin(P->phi0) / Q->alpha); g = pow( (1. + P->e * sin(P->phi0)) / (1. - P->e * sin(P->phi0)) , Q->alpha * P->e / 2. ); - Q->k = tan( u0 / 2. + M_PI_4) / pow (tan(P->phi0 / 2. + M_PI_4) , Q->alpha) * g; + double tan_half_phi0_plus_pi_4 = tan(P->phi0 / 2. + M_PI_4); + if( tan_half_phi0_plus_pi_4 == 0.0 ) { + return pj_default_destructor(P, PJD_ERR_INVALID_ARG); + } + Q->k = tan( u0 / 2. + M_PI_4) / pow (tan_half_phi0_plus_pi_4 , Q->alpha) * g; n0 = sqrt(1. - P->es) / (1. - P->es * pow(sin(P->phi0), 2)); Q->n = sin(S0); Q->rho0 = P->k0 * n0 / tan(S0); diff --git a/src/projections/lcc.cpp b/src/projections/lcc.cpp index 55d28b80..8cc743a9 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 ) { @@ -125,6 +125,9 @@ PJ *PROJECTION(lcc) { Q->rho0 *= (fabs(fabs(P->phi0) - M_HALFPI) < EPS10) ? 0. : pow(pj_tsfn(P->phi0, sin(P->phi0), P->e), Q->n); } else { + if( fabs(cosphi) < EPS10 || fabs(cos(Q->phi2)) < EPS10 ) { + return pj_default_destructor(P, PJD_ERR_LAT_1_OR_2_ZERO_OR_90); + } if (secant) Q->n = log(cosphi / cos(Q->phi2)) / log(tan(M_FORTPI + .5 * Q->phi2) / 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..5cbe6325 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 @@ -2115,6 +2115,25 @@ expect -0.001796699 0.500904924 accept -200 -100 expect -0.001796698 0.499095076 +------------------------------------------------------------------------------- +operation +proj=imw_p +ellps=GRS80 +lat_1=0 +lat_2=10 +------------------------------------------------------------------------------- +tolerance 0.1 mm +accept 0 0 +expect 0 0 +accept 0.000000000000 0.000904928485 +expect 0 100 +accept 0.000898315284 0.000000000000 +expect 100 0 + +direction inverse +accept 0 0 +expect 0 0 +accept 0 100 +expect 0.000000000000 0.000904928485 +accept 100 0 +expect 0.000898315284 0.000000000000 + =============================================================================== Icosahedral Snyder Equal Area @@ -2248,6 +2267,11 @@ expect 24.830351182 59.756888426 accept 0 0 expect 24.833333333333 59.757598563058 +------------------------------------------------------------------------------- +operation +proj=krovak +lat_0=-90 +------------------------------------------------------------------------------- +expect failure errno invalid_arg + =============================================================================== Laborde Cyl, Sph @@ -2703,7 +2727,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 @@ -2720,6 +2744,16 @@ operation +proj=lcc +ellps=GRS80 +lat_1=90 +lat_2=90 ------------------------------------------------------------------------------- expect failure errno lat_1_or_2_zero_or_90 +------------------------------------------------------------------------------- +operation +proj=lcc +ellps=sphere +lat_1=0 +lat_2=90 +------------------------------------------------------------------------------- +expect failure errno lat_1_or_2_zero_or_90 + +------------------------------------------------------------------------------- +operation +proj=lcc +ellps=sphere +lat_1=90 +lat_2=0 +------------------------------------------------------------------------------- +expect failure errno lat_1_or_2_zero_or_90 + =============================================================================== Lambert Conformal Conic Alternative Conic, Sph&Ell 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 diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index edf987ba..30e0b427 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -7334,7 +7334,8 @@ TEST(io, projparse_longlat_axis_neu) { auto op = CoordinateOperationFactory::create()->createOperation( GeographicCRS::EPSG_4326, NN_NO_CHECK(crs)); ASSERT_TRUE(op != nullptr); - EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()), "+proj=noop"); + EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=noop"); } // --------------------------------------------------------------------------- diff --git a/test/unit/test_operation.cpp b/test/unit/test_operation.cpp index c4cafef6..08a3f6ad 100644 --- a/test/unit/test_operation.cpp +++ b/test/unit/test_operation.cpp @@ -4504,7 +4504,8 @@ TEST(operation, geogCRS_to_geogCRS_noop) { GeographicCRS::EPSG_4326, GeographicCRS::EPSG_4326); ASSERT_TRUE(op != nullptr); EXPECT_EQ(op->nameStr(), "Null geographic offset from WGS 84 to WGS 84"); - EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()), "+proj=noop"); + EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=noop"); EXPECT_EQ(op->inverse()->nameStr(), op->nameStr()); } @@ -4845,7 +4846,8 @@ TEST(operation, geocentricCRS_to_geocentricCRS_noop) { ASSERT_TRUE(op != nullptr); EXPECT_EQ(op->nameStr(), "Ballpark geocentric translation from WGS 84 to WGS 84"); - EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()), "+proj=noop"); + EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=noop"); EXPECT_EQ(op->inverse()->nameStr(), op->nameStr()); } |
