aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2017-05-23 17:37:42 +0200
committerKristian Evers <kristianevers@gmail.com>2017-05-23 21:07:02 +0200
commita54611f16cf2140d93f8a33563bbc79af136636a (patch)
tree32f2962f8c042ab89734e18c8a7a3d4b5f35828a /src
parent8110056d51ff94f4bc545a10306915f442cdc839 (diff)
downloadPROJ-a54611f16cf2140d93f8a33563bbc79af136636a.tar.gz
PROJ-a54611f16cf2140d93f8a33563bbc79af136636a.zip
Fix possible zero division.
For some extreme values of eccentricity a zero divison can occur. In those rare cases we return HUGE_VAL to indicate something went wrong while still returning a defined value. Credit to OSS Fuzz. https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=1801
Diffstat (limited to 'src')
-rw-r--r--src/pj_tsfn.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/pj_tsfn.c b/src/pj_tsfn.c
index 448aae99..eff20cab 100644
--- a/src/pj_tsfn.c
+++ b/src/pj_tsfn.c
@@ -2,9 +2,15 @@
#include <math.h>
#include <projects.h>
- double
-pj_tsfn(double phi, double sinphi, double e) {
- sinphi *= e;
- return (tan (.5 * (M_HALFPI - phi)) /
- pow((1. - sinphi) / (1. + sinphi), .5 * e));
+double pj_tsfn(double phi, double sinphi, double e) {
+ double denominator;
+ sinphi *= e;
+
+ /* avoid zero division, fail gracefully */
+ denominator = 1.0 + sinphi;
+ if (denominator == 0.0)
+ return HUGE_VAL;
+
+ return (tan (.5 * (M_HALFPI - phi)) /
+ pow((1. - sinphi) / (denominator), .5 * e));
}