aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-03-16 01:51:05 +0100
committerEven Rouault <even.rouault@spatialys.com>2019-03-16 10:10:03 +0100
commitc6f41f0176d744de5de1ca48e764148ed18e6489 (patch)
tree997fa57dff06651313530323ecd215b464f7bfdc /src
parentb81d78b291658438c91a50995e546c853ef5ef7a (diff)
downloadPROJ-c6f41f0176d744de5de1ca48e764148ed18e6489.tar.gz
PROJ-c6f41f0176d744de5de1ca48e764148ed18e6489.zip
ocea: avoid division by zero
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11699 Credit to OSS Fuzz
Diffstat (limited to 'src')
-rw-r--r--src/projections/ocea.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/projections/ocea.cpp b/src/projections/ocea.cpp
index 4930e587..4e28f727 100644
--- a/src/projections/ocea.cpp
+++ b/src/projections/ocea.cpp
@@ -87,7 +87,16 @@ PJ *PROJECTION(ocea) {
lam_p = -lam_p;
/*Equation 9-2 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
- phi_p = atan(-cos(lam_p - lam_1) / tan(phi_1));
+ double cos_lamp_m_minus_lam_1 = cos(lam_p - lam_1);
+ double tan_phi_1 = tan(phi_1);
+ if( tan_phi_1 == 0.0 ) {
+ // Not sure if we want to support this case, but at least this avoids
+ // a division by zero, and gives the same result as the below atan()
+ phi_p = (cos_lamp_m_minus_lam_1 >= 0.0 ) ? -M_HALFPI : M_HALFPI;
+ }
+ else {
+ phi_p = atan(- cos_lamp_m_minus_lam_1 / tan_phi_1);
+ }
}
P->lam0 = lam_p + M_HALFPI;
Q->cosphi = cos(phi_p);