Open tvf opened 4 years ago
I'm using GCC 7.4 on Ubuntu 18.04.4 LTS. Building with -fsanitize=address
reports a stack buffer overflow.
I investigated this and the root cause of the problem lies in polygon_set_data<int>::clean()
. There's a specific issue of two of the input line segments where compute_exact_intersection
fails to, well, compute the exact intersection. This results in inconsistent geometry/violated preconditions of other functions and becomes a segfault way down the line.
It turns out that this kind of behaviour is expected (see https://lists.boost.org/boost-users/2010/11/63944.php) because the default implementation of compute_exact_intersection
uses long double
to compute the intersection points, which can produce incorrectly rounded results in certain cases.
A simple solution is to link the library against GMP by using the gmp_override.hpp
header. This fixes the example presented here.
I think there are two approaches to prevent this kind of problem for users of the library:
gmp_override.hpp
whenever you include polygon.hpp
is error-prone. A simple solution would be to provide a feature macro that automatically configures the library for this kind of usage.compute_exact_intersection
in its default state, i.e., using long double
. It is relatively easy to come up with a quick win here (and my prototype fixes the segfault in this example), but I'm not sure/haven't analysed whether the issue can be fixed for all possible input values, and in a portable way.@asydorchuk Could you let me know which of these solutions (if any) you would consider for inclusion in the library? I would be happy to raise a PR. Thank you.
The following program crashes with a segmentation fault inside the
get()
call. I've tested against1.65
,1.72
, and currentmaster
. I'm pretty sure that this usage falls inside the API contract, but perhaps I'm missing something?