aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-07-16 14:42:37 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-07-16 14:42:37 -0400
commit884bae143c235981e53eae4ea56c47060740e3ee (patch)
tree776082b973595ae72bb4dc9781dc484126435812
parent1f9534b49ce3ab02aac65c4033218cc3348d17b8 (diff)
downloadpostgresql-884bae143c235981e53eae4ea56c47060740e3ee.tar.gz
postgresql-884bae143c235981e53eae4ea56c47060740e3ee.zip
Fix crash in close_ps() for NaN input coordinates.
The Assert() here seems unreasonably optimistic. Andreas Seltenreich found that it could fail with NaNs in the input geometries, and it seems likely to me that it might fail in corner cases due to roundoff error, even for ordinary input values. As a band-aid, make the function return SQL NULL instead of crashing. Report: <87d1md1xji.fsf@credativ.de>
-rw-r--r--src/backend/utils/adt/geo_ops.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c
index ad48dfcb4b7..dfb71a2f4ed 100644
--- a/src/backend/utils/adt/geo_ops.c
+++ b/src/backend/utils/adt/geo_ops.c
@@ -2914,7 +2914,7 @@ close_ps(PG_FUNCTION_ARGS)
}
/*
- * at this point the "normal" from point will hit lseg. The closet point
+ * at this point the "normal" from point will hit lseg. The closest point
* will be somewhere on the lseg
*/
tmp = line_construct_pm(pt, invm);
@@ -2923,7 +2923,15 @@ close_ps(PG_FUNCTION_ARGS)
tmp->A, tmp->B, tmp->C);
#endif
result = interpt_sl(lseg, tmp);
- Assert(result != NULL);
+
+ /*
+ * ordinarily we should always find an intersection point, but that could
+ * fail in the presence of NaN coordinates, and perhaps even from simple
+ * roundoff issues. Return a SQL NULL if so.
+ */
+ if (result == NULL)
+ PG_RETURN_NULL();
+
#ifdef GEODEBUG
printf("close_ps- result.x %f result.y %f\n", result->x, result->y);
#endif