Giter Club home page Giter Club logo

Comments (7)

dbaston avatar dbaston commented on July 22, 2024 2

With branch prediction I'd guess the GEOS penalty vanishes into the overhead of the C API. We already have some similar idiot-proofing like checking for a null pointer on every C API call.

from geos.

dbaston avatar dbaston commented on July 22, 2024

Thanks for the detailed write-up. I can see both sides: (1) that it's really on the caller (QgsGeos::fromGeos) to be checking whether a geometry has any coordinates before reading them, and ; yet (2) GEOSCoordSeq_getXYZ_r returns an error code, so it should do a bounds-check instead of crashing.

I haven't checked to see why this is a new crash, or whether GEOS previously provided a coordinate from an empty geometry, but I can't think of a reason why it should have done so.

from geos.

pramsey avatar pramsey commented on July 22, 2024

I wonder how much more expensive checking on every access (fix in geos) is vs checking before starting to access (fix in qgis).

from geos.

gszy avatar gszy commented on July 22, 2024

GEOSCoordSeq_getXYZ_r returns an error code, so it should do a bounds-check instead of crashing.

Or the check could be done in FixedSizeCoordinateSequence. I don’t know if there are other kinds of sequences, but this one certainly can segfault.

I haven't checked to see why this is a new crash

FWIW, it wasn’t crashing with QGIS 3.4.15 and GEOS 3.8.0 (Debian testing).

from geos.

dbaston avatar dbaston commented on July 22, 2024

Or the check could be done in FixedSizeCoordinateSequence. I don’t know if there are other kinds of sequences, but this one certainly can segfault.

Whether bounds checking is performed or not should not depend on the type of coordinate sequence. The more I think about it, the less I see the desirability. Should we also check that one does not access a subgeometry that does not exist? At some point, yes, you can expect compiled code to crash when you try to access elements out of bounds. That's not really unique to GEOS.

from geos.

gszy avatar gszy commented on July 22, 2024

Whether bounds checking is performed or not should not depend on the type of coordinate sequence.

I meant that FixedSizeCoordinateSequence uses a std::array internally and relies on operator[] which does no bound checking. “Crashing” is the way std::array::operator[] works, while throwing an exception could be part of CoordinateSequence::getAt()’s interface.

Should we also check that one does not access a subgeometry that does not exist?

Is std::vector (this one) an implementation detail or GeometryCollection’s interface?

Both cases boil down to a design decision: GEOS should either validate (more) input data (https://git.osgeo.org/gitea/geos/geos/pulls/103) or, well, it would be nice to at least document the current behavior, though I’m afraid it wouldn’t prevent this crash…

At some point, yes, you can expect compiled code to crash when you try to access elements out of bounds.

Actually, according to https://www.cplusplus.com/reference/vector/vector/operator[]/, std::vector::operator[] causes undefined behavior, so maybe it won’t crash when it should. Throwing an exception would probably be safer. I don’t know C++ well enough.

from geos.

nyalldawson avatar nyalldawson commented on July 22, 2024

For reference- an explicit point count check was added to QGIS in qgis/QGIS@774f1db . This can be closed now if the geos project deems that an automatic check at the geos level is too costly.

from geos.

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.