From a54611f16cf2140d93f8a33563bbc79af136636a Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Tue, 23 May 2017 17:37:42 +0200 Subject: 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 --- src/pj_tsfn.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') 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 #include - 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)); } -- cgit v1.2.3