Comments (7)
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.
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.
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.
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.
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.
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.
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)
- Possible backport for concaveHull HOT 7
- OffsetCurve produces MultiLineString with 2 contiguous lines
- Offset curve issue with closed linestring and miter join HOT 2
- [FR] optional GPU acceleration using OpenCL or Vulkan Compute HOT 1
- Overlapping Voronoi output from four input points HOT 1
- Negative buffer with `join-style` mitre HOT 9
- "Divide by zero" warning when `difference` is applied HOT 6
- "Invalid value" warning when `difference` is applied HOT 4
- Union on 3 Polygons results in a MultiPolygon with 1 Polygon HOT 4
- ST_Relate gives incorrect result for interior-interior intersection dimension HOT 2
- Build fails with LTO (odr violations)
- Reducing precision results in empty polygon unnecessarily (GEOSGeom_setPrecision) HOT 12
- Unexpected result for intersection of Geometrycollection with polygon? HOT 2
- Relate algorithm Issue Summary
- AssertionFailedException: found two shells in EdgeRing list HOT 1
- Voronoi diagram contains collection with a LineString
- Union doesn't merge linestrings... HOT 3
- RelateCompute intersection report inconsistent for lines and boundary points HOT 5
- There seems to be a circular reference in WKT BNF HOT 2
- Performance optimisation of point-to-point distance HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geos.