aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-03-24 17:05:11 +0100
committerEven Rouault <even.rouault@spatialys.com>2019-03-24 17:05:11 +0100
commit0529b07f81d3c027e101c6e1eddb4685e957934d (patch)
tree6a709dcb322c08ceac03478867d2afb9269eac24
parentad889fc63abd2b1352e107c947ed589108cc7bc0 (diff)
downloadPROJ-0529b07f81d3c027e101c6e1eddb4685e957934d.tar.gz
PROJ-0529b07f81d3c027e101c6e1eddb4685e957934d.zip
tmerc inverse: avoid division by zero
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=13893 Credit to OSS Fuzz
-rw-r--r--src/projections/tmerc.cpp4
-rw-r--r--test/gie/builtins.gie8
2 files changed, 12 insertions, 0 deletions
diff --git a/src/projections/tmerc.cpp b/src/projections/tmerc.cpp
index c91c5174..bb56f8ae 100644
--- a/src/projections/tmerc.cpp
+++ b/src/projections/tmerc.cpp
@@ -188,6 +188,10 @@ static PJ_LP approx_s_inv (PJ_XY xy, PJ *P) {
double h, g;
h = exp(xy.x / static_cast<struct pj_opaque_approx*>(P->opaque)->esp);
+ if( h == 0 ) {
+ proj_errno_set(P, PJD_ERR_INVALID_X_OR_Y);
+ return proj_coord_error().lp;
+ }
g = .5 * (h - 1. / h);
h = cos (P->phi0 + xy.y / static_cast<struct pj_opaque_approx*>(P->opaque)->esp);
lp.phi = asin(sqrt((1. - h * h) / (1. + g * g)));
diff --git a/test/gie/builtins.gie b/test/gie/builtins.gie
index a28ff45c..f0290fa2 100644
--- a/test/gie/builtins.gie
+++ b/test/gie/builtins.gie
@@ -5058,6 +5058,14 @@ expect -0.001790493 0.000895247
accept -200 -100
expect -0.001790493 -0.000895247
+
+-------------------------------------------------------------------------------
+operation +proj=tmerc +R=1
+-------------------------------------------------------------------------------
+direction inverse
+accept -1e200 0
+expect failure errno invalid_x_or_y
+
===============================================================================
Tobler-Mercator
Cyl, Sph