ivanfratric/polypartition

Invalid memory access case when invalid polygons are given

Closed this issue · 1 comments

I'm currently using this very useful piece of code in one of my programs, and came across a nasty little behaviour in one of my study cases. I understand this is not really a bug in the library, given that the code assumes all input polygons are valid (n>2), however there were consequences in the rest of my code in this case so I thought I'd bring it up in case someone ever comes across it again.

When an invalid polygon is given to Triangulate_OPT, the first index used on the dpstates array may be invalid (among other things). While it may not necessarily trigger an error at that exact spot, it can cause corruptions which later propagate and mislead debugging (as it was the case for me).

Would it be possible for the library to check the validity of its TPPLPoly objects before it manipulates them? I've added this check in my code (I should anyway), but without valgrind and massif (which conveniently had a little oops for my distro a few days ago), it was particularly tricky to trace back the error to an invalid polygon. Now that I'm using upstream valgrind, I can confirm that it reports Use of uninitialised value, Bad permissions for mapped region or Access not within mapped region.

Hi Julien, would you be willing to submit a patch? You seem to have looked into this quite a bit.