From 586ef0f5f1099fa7aaaa353334e15871ab985127 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 30 Oct 2022 10:01:26 +0100 Subject: [PATCH] eqdc: avoid floating point division by zero in non-nominal case. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52879 --- src/projections/eqdc.cpp | 8 ++++++-- test/gie/builtins.gie | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/projections/eqdc.cpp b/src/projections/eqdc.cpp index 4407ab62c3..325b5613be 100644 --- a/src/projections/eqdc.cpp +++ b/src/projections/eqdc.cpp @@ -119,8 +119,12 @@ PJ *PROJECTION(eqdc) { if (secant) { /* secant cone */ sinphi = sin(Q->phi2); cosphi = cos(Q->phi2); - Q->n = (m1 - pj_msfn(sinphi, cosphi, P->es)) / - (pj_mlfn(Q->phi2, sinphi, cosphi, Q->en) - ml1); + const double ml2 = pj_mlfn(Q->phi2, sinphi, cosphi, Q->en); + if (ml1 == ml2) { + proj_log_error(P, _("Eccentricity too close to 1")); + return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + } + Q->n = (m1 - pj_msfn(sinphi, cosphi, P->es)) / (ml2 - ml1); if (Q->n == 0) { // Not quite, but es is very close to 1... proj_log_error(P, _("Invalid value for eccentricity")); diff --git a/test/gie/builtins.gie b/test/gie/builtins.gie index 2b088b00af..5f99497d7c 100644 --- a/test/gie/builtins.gie +++ b/test/gie/builtins.gie @@ -1375,6 +1375,9 @@ expect failure errno invalid_op_illegal_arg_value operation +proj=eqdc +R=1 +lat_1=1e-9 expect failure errno invalid_op_illegal_arg_value +operation +proj=eqdc +lat_1=1 +ellps=GRS80 +b=.1 +expect failure errno invalid_op_illegal_arg_value + =============================================================================== # Euler # Conic, Sph