Coder Social home page Coder Social logo

Comments (3)

tvf avatar tvf commented on July 17, 2024

I'm using GCC 7.4 on Ubuntu 18.04.4 LTS. Building with -fsanitize=address reports a stack buffer overflow.

from polygon.

dmsteck avatar dmsteck commented on July 17, 2024

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.

from polygon.

dmsteck avatar dmsteck commented on July 17, 2024

I think there are two approaches to prevent this kind of problem for users of the library:

  • Make it more obvious that the library should be used with GMP, and make it easier to use the library in that way. Including 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.
  • A more ambitious alternative would be to attempt to fix 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.

from polygon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.