Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2781489

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 745513c commit 2781489

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/backend/utils/adt/geo_ops.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -2848,7 +2848,7 @@ close_ps(PG_FUNCTION_ARGS)
28482848
}
28492849

28502850
/*
2851-
* at this point the "normal" from point will hit lseg. The closet point
2851+
* at this point the "normal" from point will hit lseg. The closest point
28522852
* will be somewhere on the lseg
28532853
*/
28542854
tmp = line_construct_pm(pt, invm);
@@ -2857,7 +2857,15 @@ close_ps(PG_FUNCTION_ARGS)
28572857
tmp->A, tmp->B, tmp->C);
28582858
#endif
28592859
result = interpt_sl(lseg, tmp);
2860-
Assert(result != NULL);
2860+
2861+
/*
2862+
* ordinarily we should always find an intersection point, but that could
2863+
* fail in the presence of NaN coordinates, and perhaps even from simple
2864+
* roundoff issues. Return a SQL NULL if so.
2865+
*/
2866+
if (result == NULL)
2867+
PG_RETURN_NULL();
2868+
28612869
#ifdef GEODEBUG
28622870
printf("close_ps- result.x %f result.y %f\n", result->x, result->y);
28632871
#endif

0 commit comments

Comments
 (0)