8000 Fix crash in close_ps() for NaN input coordinates. · rtpg/postgres@884bae1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 884bae1

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 1f9534b commit 884bae1

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
@@ -2914,7 +2914,7 @@ close_ps(PG_FUNCTION_ARGS)
29142914
}
29152915

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

0 commit comments

Comments
 (0)
0