Skip to content

Commit 16e28fc

Browse files
committed
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>
1 parent 2e51ae1 commit 16e28fc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/backend/utils/adt/geo_ops.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,7 @@ close_ps(PG_FUNCTION_ARGS)
29132913
}
29142914

29152915
/*
2916-
* at this point the "normal" from point will hit lseg. The closet point
2916+
* at this point the "normal" from point will hit lseg. The closest point
29172917
* will be somewhere on the lseg
29182918
*/
29192919
tmp = line_construct_pm(pt, invm);
@@ -2922,7 +2922,15 @@ close_ps(PG_FUNCTION_ARGS)
29222922
tmp->A, tmp->B, tmp->C, tmp->m);
29232923
#endif
29242924
result = interpt_sl(lseg, tmp);
2925-
Assert(result != NULL);
2925+
2926+
/*
2927+
* ordinarily we should always find an intersection point, but that could
2928+
* fail in the presence of NaN coordinates, and perhaps even from simple
2929+
* roundoff issues. Return a SQL NULL if so.
2930+
*/
2931+
if (result == NULL)
2932+
PG_RETURN_NULL();
2933+
29262934
#ifdef GEODEBUG
29272935
printf("close_ps- result.x %f result.y %f\n", result->x, result->y);
29282936
#endif

0 commit comments

Comments
 (0)