diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-09-18 16:57:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-18 16:57:19 +0200 |
| commit | 72203ca68e123a237c8c748d39131b702ea4b646 (patch) | |
| tree | 38d1214e399eaaf4e173ad5d13a3820364065c1d | |
| parent | d2f661fc99615a33d72bb0120a14bca2aaced221 (diff) | |
| parent | bc53524cfbde95ecf6bb134984e68eb715d11c2b (diff) | |
| download | PROJ-72203ca68e123a237c8c748d39131b702ea4b646.tar.gz PROJ-72203ca68e123a237c8c748d39131b702ea4b646.zip | |
Merge pull request #1620 from rouault/ossfuzz_17190_and_others
Assorted set of fixes for boring oss-fuzz related errors (mostly divisions by zero in odd situations)
| -rw-r--r-- | src/ell_set.cpp | 3 | ||||
| -rw-r--r-- | src/geocent.cpp | 24 | ||||
| -rw-r--r-- | src/projections/aea.cpp | 4 | ||||
| -rw-r--r-- | src/projections/eqdc.cpp | 2 | ||||
| -rw-r--r-- | src/projections/geos.cpp | 8 | ||||
| -rw-r--r-- | src/projections/isea.cpp | 2 | ||||
| -rw-r--r-- | src/transformations/helmert.cpp | 2 | ||||
| -rw-r--r-- | test/fuzzers/standard_fuzzer.cpp | 6 | ||||
| -rw-r--r-- | test/gie/builtins.gie | 3 | ||||
| -rw-r--r-- | test/gie/ellipsoid.gie | 2 |
10 files changed, 49 insertions, 7 deletions
diff --git a/src/ell_set.cpp b/src/ell_set.cpp index 0d7fb6d5..d2930ca4 100644 --- a/src/ell_set.cpp +++ b/src/ell_set.cpp @@ -389,6 +389,9 @@ static int ellps_spherification (PJ *P) { return proj_errno_set (P, PJD_ERR_REF_RAD_LARGER_THAN_90); t = sin (t); t = 1 - P->es * t * t; + if (t == 0.) { + return proj_errno_set(P, PJD_ERR_INVALID_ECCENTRICITY); + } if (i==5) /* arithmetic */ P->a *= (1. - P->es + t) / (2 * t * sqrt(t)); else /* geometric */ diff --git a/src/geocent.cpp b/src/geocent.cpp index c023bdd3..cbcc1df5 100644 --- a/src/geocent.cpp +++ b/src/geocent.cpp @@ -399,7 +399,17 @@ void pj_Convert_Geocentric_To_Geodetic (GeocentricInfo *gi, */ CT = Z/RR; ST = P/RR; - RX = 1.0/sqrt(1.0-gi->Geocent_e2*(2.0-gi->Geocent_e2)*ST*ST); + { + const double denominator = 1.0-gi->Geocent_e2*(2.0-gi->Geocent_e2)*ST*ST; + if( denominator == 0 ) + { + *Latitude = HUGE_VAL; + *Longitude = HUGE_VAL; + *Height = HUGE_VAL; + return; + } + RX = 1.0/sqrt(denominator); + } CPHI0 = ST*(1.0-gi->Geocent_e2)*RX; SPHI0 = CT*RX; iter = 0; @@ -420,7 +430,17 @@ void pj_Convert_Geocentric_To_Geodetic (GeocentricInfo *gi, return; } RK = gi->Geocent_e2*RN/(RN+*Height); - RX = 1.0/sqrt(1.0-RK*(2.0-RK)*ST*ST); + { + const double denominator = 1.0-RK*(2.0-RK)*ST*ST; + if( denominator == 0 ) + { + *Latitude = HUGE_VAL; + *Longitude = HUGE_VAL; + *Height = HUGE_VAL; + return; + } + RX = 1.0/sqrt(denominator); + } CPHI = ST*(1.0-RK)*RX; SPHI = CT*RX; SDPHI = SPHI*CPHI0-CPHI*SPHI0; diff --git a/src/projections/aea.cpp b/src/projections/aea.cpp index 721ea3c9..d607c95a 100644 --- a/src/projections/aea.cpp +++ b/src/projections/aea.cpp @@ -127,6 +127,10 @@ static PJ_LP aea_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoid/spheroid, inverse if (Q->ellips) { lp.phi = (Q->c - lp.phi * lp.phi) / Q->n; if (fabs(Q->ec - fabs(lp.phi)) > TOL7) { + if (fabs(lp.phi) > 2 ) { + proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION); + return lp; + } if ((lp.phi = phi1_(lp.phi, P->e, P->one_es)) == HUGE_VAL) { proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION); return lp; diff --git a/src/projections/eqdc.cpp b/src/projections/eqdc.cpp index e050a593..00aacfda 100644 --- a/src/projections/eqdc.cpp +++ b/src/projections/eqdc.cpp @@ -117,6 +117,8 @@ PJ *PROJECTION(eqdc) { } else { if (secant) Q->n = (cosphi - cos(Q->phi2)) / (Q->phi2 - Q->phi1); + if (Q->n == 0) + return destructor (P, PJD_ERR_CONIC_LAT_EQUAL); Q->c = Q->phi1 + cos(Q->phi1) / Q->n; Q->rho0 = Q->c - P->phi0; } diff --git a/src/projections/geos.cpp b/src/projections/geos.cpp index 15f51e6f..7999b21f 100644 --- a/src/projections/geos.cpp +++ b/src/projections/geos.cpp @@ -126,11 +126,11 @@ static PJ_LP geos_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse /* Setting three components of vector from satellite to position.*/ Vx = -1.0; if(Q->flip_axis) { - Vz = tan (xy.y / (Q->radius_g - 1.0)); - Vy = tan (xy.x / (Q->radius_g - 1.0)) * sqrt (1.0 + Vz * Vz); + Vz = tan (xy.y / Q->radius_g_1); + Vy = tan (xy.x / Q->radius_g_1) * sqrt (1.0 + Vz * Vz); } else { - Vy = tan (xy.x / (Q->radius_g - 1.0)); - Vz = tan (xy.y / (Q->radius_g - 1.0)) * sqrt (1.0 + Vy * Vy); + Vy = tan (xy.x / Q->radius_g_1); + Vz = tan (xy.y / Q->radius_g_1) * sqrt (1.0 + Vy * Vy); } /* Calculation of terms in cubic equation and determinant.*/ diff --git a/src/projections/isea.cpp b/src/projections/isea.cpp index c22e143d..d1aeab4a 100644 --- a/src/projections/isea.cpp +++ b/src/projections/isea.cpp @@ -902,7 +902,7 @@ static int isea_hex(struct isea_dgg *g, int tri, { throw "Invalid shift"; } - hex->x = ((int)v.x << 4) + quad; + hex->x = ((int)v.x * 16) + quad; hex->y = v.y; return 1; diff --git a/src/transformations/helmert.cpp b/src/transformations/helmert.cpp index 63785ea5..7a3e64d0 100644 --- a/src/transformations/helmert.cpp +++ b/src/transformations/helmert.cpp @@ -612,6 +612,8 @@ PJ *TRANSFORMATION(helmert, 0) { /* Scale */ if (pj_param (P->ctx, P->params, "ts").i) { Q->scale_0 = pj_param (P->ctx, P->params, "ds").f; + if( Q->scale_0 <= -1.0e6 ) + return pj_default_destructor (P, PJD_ERR_INVALID_SCALE); if (pj_param (P->ctx, P->params, "ttheta").i && Q->scale_0 == 0.0) return pj_default_destructor (P, PJD_ERR_INVALID_SCALE); } diff --git a/test/fuzzers/standard_fuzzer.cpp b/test/fuzzers/standard_fuzzer.cpp index 11f8738e..29ea50f8 100644 --- a/test/fuzzers/standard_fuzzer.cpp +++ b/test/fuzzers/standard_fuzzer.cpp @@ -105,8 +105,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) { free(buf_dup); pj_free(pj_src); +#ifndef OMIT_DEALLOCATION pj_gc_unloadall(pj_get_default_ctx()); pj_deallocate_grids(); +#endif return 0; } double x = 0, y = 0, z = 9; @@ -133,8 +135,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) free(buf_dup); pj_free(pj_src); pj_free(pj_dst); +#ifndef OMIT_DEALLOCATION pj_gc_unloadall(pj_get_default_ctx()); pj_deallocate_grids(); +#endif return 0; } #ifdef STANDALONE @@ -157,8 +161,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) free(buf_dup); pj_free(pj_src); pj_free(pj_dst); +#ifndef OMIT_DEALLOCATION pj_gc_unloadall(pj_get_default_ctx()); pj_deallocate_grids(); +#endif return 0; } diff --git a/test/gie/builtins.gie b/test/gie/builtins.gie index df19efb6..3397090c 100644 --- a/test/gie/builtins.gie +++ b/test/gie/builtins.gie @@ -1321,6 +1321,9 @@ expect failure errno lat_larger_than_90 operation +proj=eqdc +R=6400000 +lat_2=91 expect failure errno lat_larger_than_90 +operation +proj=eqdc +R=1 +lat_1=1e-9 +expect failure errno conic_lat_equal + =============================================================================== Euler Conic, Sph diff --git a/test/gie/ellipsoid.gie b/test/gie/ellipsoid.gie index b84a512f..74fbe31d 100644 --- a/test/gie/ellipsoid.gie +++ b/test/gie/ellipsoid.gie @@ -116,6 +116,8 @@ accept 12 55 expect 1338073.2696101593 7374207.4801437631 ------------------------------------------------------------------------------- +operation proj=merc a=1E77 R_lat_a=90 b=1 +expect failure errno invalid_eccentricity ------------------------------------------------------------------------------- This one from testvarious failed at first version of the pull request |
