On Mon, Feb 28, 2011 at 16:35, Mark Cave-Ayland
<mark.cave-ayl...@siriusit.co.uk> wrote:
> On 28/02/11 15:18, Magnus Hagander wrote:
>
>> Hi!
>>
>> Running the following query locks up postgis completely (in
>> geos::algorithm::RobustDeterminant):
>>
>> SELECT st_intersects(somegeometry,
>>
>> '0103000020E61000000100000005000000737979F3DDCC2CC0F92154F9E7534540000000000000F07F000000000000F07F8F806E993F7E55C0304B29FFEA8554400634E8D1DD424540B5FEE6A37FCD4540737979F3DDCC2CC0F92154F9E7534540'::geometry)
>>
>> I believe this is because there are infinite values in that geometry:
>>
>> # select
>> ST_AsText('0103000020E61000000100000005000000737979F3DDCC2CC0F92154F9E7534540000000000000F07F000000000000F07F8F806E993F7E55C0304B29FFEA8554400634E8D1DD424540B5FEE6A37FCD4540737979F3DDCC2CC0F92154F9E7534540'::geometry);
>>
>>   st_astext
>>
>> ---------------------------------------------------------------------------------------------------------------------------------------------------------------
>>  POLYGON((-14.4001308522972 42.6555167828373,inf inf,-85.9726317957995
>> 82.0924680617579,42.5223944076352 43.6054577711015,-14.4001308522972
>> 42.6555167828373))
>> (1 row)
>>
>>
>> ISTM that this should either be rejected as an invalid geometry, or at
>> least not hang....
>
> Hi Magnus,
>
> Hmmmm - I can definitely reproduce this on trunk with GEOS 3.2 series. The
> backtrace from inside GEOS looks like this:

Since nobody appears to be too interested in producing a quick fix in
geos, attached is a patch that puts in an *ugly* workaround in
PostGIS, that simply rejects the infinite values higher up in the
stack. I don't consider this a long-term fix, but it at least causes
an error instead of getting stuck in an infinite loop that can only be
terminated with kill -9... So pending a solution in geos, I would
suggest this workaround (or something better located written by
someone who actually know the postgis code better than me) be put in.
The way it is now, any application that allows the user to specify
input that could generate such a geometry could trivially
denial-of-service any postgis site...

-- 
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/
Index: postgis/lwgeom_geos.c
===================================================================
--- postgis/lwgeom_geos.c	(revision 6880)
+++ postgis/lwgeom_geos.c	(working copy)
@@ -2215,6 +2215,26 @@
 		{
 			PG_RETURN_BOOL(FALSE);
 		}
+
+		/*
+		 * If any of the geometries contain infinity, just error out,
+		 * because if it's passed to the intersects functions it causes
+		 * infinite loops that cannot be broken with query cancel or
+		 * even session terminate.
+		 *
+		 * XXX: mha: This should be fixed in the underlying libraries! This
+		 * is just a workaround!
+		 */
+		if (isinf(box1.xmin) || isinf(box1.xmax) ||
+			isinf(box1.ymin) || isinf(box1.ymax))
+			ereport(ERROR,
+					(errmsg("infinite value found in geometry %i, cannot run intersects()",
+							1)));
+		if (isinf(box2.xmin) || isinf(box2.xmax) ||
+			isinf(box2.ymin) || isinf(box2.ymax))
+			ereport(ERROR,
+					(errmsg("infinite value found in geometry %i, cannot run intersects()",
+							2)));
 	}
 
 	/*
_______________________________________________
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

Reply via email to