aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@mines-paris.org>2017-05-23 22:08:36 +0200
committerGitHub <noreply@github.com>2017-05-23 22:08:36 +0200
commitadc03319ef5e79f69524431e7718a30752f659fe (patch)
treebe3d2874b150289edfe8f3694adc3ce259c770c5 /src
parenta54611f16cf2140d93f8a33563bbc79af136636a (diff)
parent9ebed249a6c8957b345396f6085090f7d2cd0e47 (diff)
downloadPROJ-adc03319ef5e79f69524431e7718a30752f659fe.tar.gz
PROJ-adc03319ef5e79f69524431e7718a30752f659fe.zip
Merge pull request #518 from rouault/fix_ossfuzz_1809
Avoid potentially very long loop when normalizing longitudes around long_wrap_center
Diffstat (limited to 'src')
-rw-r--r--src/pj_init.c13
-rw-r--r--src/pj_transform.c14
2 files changed, 18 insertions, 9 deletions
diff --git a/src/pj_init.c b/src/pj_init.c
index fefcb8fa..6568033f 100644
--- a/src/pj_init.c
+++ b/src/pj_init.c
@@ -559,7 +559,16 @@ pj_init_ctx(projCtx ctx, int argc, char **argv) {
/* longitude center for wrapping */
PIN->is_long_wrap_set = pj_param(ctx, start, "tlon_wrap").i;
if (PIN->is_long_wrap_set)
+ {
PIN->long_wrap_center = pj_param(ctx, start, "rlon_wrap").f;
+ /* Don't accept excessive values otherwise we might perform badly */
+ /* when correcting longitudes around it */
+ if( !(fabs(PIN->long_wrap_center) < 10 * M_TWOPI) )
+ {
+ pj_ctx_set_errno( ctx, -14 );
+ goto bum_call;
+ }
+ }
/* axis orientation */
if( (pj_param(ctx, start,"saxis").s) != NULL )
@@ -584,10 +593,6 @@ pj_init_ctx(projCtx ctx, int argc, char **argv) {
strcpy( PIN->axis, axis_arg );
}
- PIN->is_long_wrap_set = pj_param(ctx, start, "tlon_wrap").i;
- if (PIN->is_long_wrap_set)
- PIN->long_wrap_center = pj_param(ctx, start, "rlon_wrap").f;
-
/* central meridian */
PIN->lam0=pj_param(ctx, start, "rlon_0").f;
diff --git a/src/pj_transform.c b/src/pj_transform.c
index 6e48948d..212d8842 100644
--- a/src/pj_transform.c
+++ b/src/pj_transform.c
@@ -422,13 +422,17 @@ int pj_transform( PJ *srcdefn, PJ *dstdefn, long point_count, int point_offset,
{
for( i = 0; i < point_count; i++ )
{
- if( x[point_offset*i] == HUGE_VAL )
+ double val = x[point_offset*i];
+ if( val == HUGE_VAL )
continue;
- while( x[point_offset*i] < dstdefn->long_wrap_center - M_PI )
- x[point_offset*i] += M_TWOPI;
- while( x[point_offset*i] > dstdefn->long_wrap_center + M_PI )
- x[point_offset*i] -= M_TWOPI;
+ /* Get fast in ] -2 PI, 2 PI [ range */
+ val = fmod(val, M_TWOPI);
+ while( val < dstdefn->long_wrap_center - M_PI )
+ val += M_TWOPI;
+ while( val > dstdefn->long_wrap_center + M_PI )
+ val -= M_TWOPI;
+ x[point_offset*i] = val;
}
}