From 4ef0b834d73931a65ad7b058159f09f246bea19e Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 4 May 2012 08:06:16 +0000 Subject: [PATCH] Protect ST_Segmentize from max_length=0 (#1799) git-svn-id: http://svn.osgeo.org/postgis/trunk@9712 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/lwgeom_functions_basic.c | 7 +++++++ regress/tickets.sql | 3 +++ regress/tickets_expected | 1 + 3 files changed, 11 insertions(+) diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index 5a3398f17..2e31c57da 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -1824,6 +1824,13 @@ Datum LWGEOM_segmentize2d(PG_FUNCTION_ARGS) PG_RETURN_POINTER(ingeom); } + if ( dist <= 0 ) { + /* Protect from knowingly infinite loops, see #1799 */ + /* Note that we'll end out of memory anyway for other small distances */ + elog(ERROR, "ST_Segmentize: invalid max_distance %g (must be >= 0)", dist); + PG_RETURN_NULL(); + } + inlwgeom = lwgeom_from_gserialized(ingeom); outlwgeom = lwgeom_segmentize2d(inlwgeom, dist); diff --git a/regress/tickets.sql b/regress/tickets.sql index fa07a57e0..c6f0dfab0 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -677,5 +677,8 @@ with inp as ( SELECT ) SELECT '#1791', round(ST_Azimuth(a,b)*10)/10 from inp; +-- #1799 -- +SELECT '#1799', ST_Segmentize('LINESTRING(0 0, 10 0)'::geometry, 0); + -- Clean up DELETE FROM spatial_ref_sys; diff --git a/regress/tickets_expected b/regress/tickets_expected index 50ee58d60..31d24b6f3 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -219,3 +219,4 @@ NOTICE: SRID value -1 converted to the officially unknown SRID value 0 #1755|01010000A0E6100000000000000040554000000000008041400000000000000000 #1776|POLYGON((0 0,10 0,10 10,0 0))|POLYGON((0 0,10 0,10 10,0 0)) #1791|4.7 +ERROR: ST_Segmentize: invalid max_distance 0 (must be >= 0) -- 2.40.0