aboutsummaryrefslogtreecommitdiff
path: root/src/geocent.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-09-17 21:01:04 +0200
committerEven Rouault <even.rouault@spatialys.com>2019-09-17 21:01:04 +0200
commit3a68912a6b556dccf22d8e8b329404821d238e50 (patch)
tree3df47a27d0cf2057e2b23a3e53449a796e13e47d /src/geocent.cpp
parent78a8f6547b29705703a997c0b4e9ce37546e119d (diff)
downloadPROJ-3a68912a6b556dccf22d8e8b329404821d238e50.tar.gz
PROJ-3a68912a6b556dccf22d8e8b329404821d238e50.zip
pj_Convert_Geocentric_To_Geodetic(): avoid division by zero on weird input coordinates and ellipsoid values. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=14766
Diffstat (limited to 'src/geocent.cpp')
-rw-r--r--src/geocent.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/geocent.cpp b/src/geocent.cpp
index c023bdd3..dd14af35 100644
--- a/src/geocent.cpp
+++ b/src/geocent.cpp
@@ -399,7 +399,15 @@ 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;