Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

POST ST_3DDifference crashes with malformed polygon #108

Closed
robe2 opened this issue Aug 26, 2015 · 17 comments
Closed

POST ST_3DDifference crashes with malformed polygon #108

robe2 opened this issue Aug 26, 2015 · 17 comments
Labels

Comments

@robe2
Copy link
Contributor

robe2 commented Aug 26, 2015

ticketed also in PostGIS at https://trac.osgeo.org/postgis/ticket/3255

This was testing with SFCGAL (1.2.0 - c2dfba1 ) on Windows 7 64-bit PostgreSQL 9.4.4

SELECT ST_3DDifference('POINT(-11.1111111 40)'::geometry, 'POLYGON((1 2,1 2,1 2,1 2))'::geometry) As result;

Backtrace looks like

#0  0x000000006d30c900 in libSFCGAL!_ZN6SFCGAL7VersionEv () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#1  0x000000006d30c93e in libSFCGAL!_ZN6SFCGAL7VersionEv () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#2  0x000000006d308601 in libSFCGAL!_ZN6SFCGAL7VersionEv () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#3  0x000000006d53a520 in libSFCGAL!_ZN6SFCGAL10LineString8addPointERKNS_5PointE () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#4  0x000000006d5395d9 in libSFCGAL!_ZN6SFCGAL10LineString8addPointERKNS_5PointE () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#5  0x000000006d53530c in libSFCGAL!_ZN6SFCGAL10LineString8addPointERKNS_5PointE () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#6  0x000000006d555c89 in libSFCGAL!_ZN6SFCGAL10LineString8addPointERKNS_5PointE () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#7  0x000000006d300118 in libSFCGAL!_ZN6SFCGAL11triangulate20triangulatePolygon3DERKNS_7PolygonERNS_19TriangulatedSurfaceE () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#8  0x000000006d2d4b6e in libSFCGAL!_ZN6SFCGAL6detaillsERSoRKNS0_11GeometrySetILi3EEE () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#9  0x000000006d505b01 in libSFCGAL!_ZN6SFCGAL10LineString8addPointERKNS_5PointE () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#10 0x000000006d506dfe in libSFCGAL!_ZN6SFCGAL10LineString8addPointERKNS_5PointE () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#11 0x000000006d25fa33 in libSFCGAL!_ZN6SFCGAL9algorithm12difference3DERKNS_8GeometryES3_NS0_15NoValidityCheckE () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#12 0x000000006d25fb3e in libSFCGAL!_ZN6SFCGAL9algorithm12difference3DERKNS_8GeometryES3_ () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#13 0x000000006d2be6e2 in sfcgal_geometry_difference_3d () from C:\ming64gcc48\projects\postgresql\rel\pg9.4w64gcc48edb\bin\libSFCGAL.dll
#14 0x000000007089260e in sfcgal_difference3D (fcinfo=0x3073a80) at lwgeom_sfcgal.c:563
#15 0x00000001401118e8 in postgres!ExecProject ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
@vmora
Copy link
Contributor

vmora commented Aug 27, 2015

Hi @robe2,

Can you plz try:

SELECT ST_IsValid('POLYGON((1 2,1 2,1 2,1 2))'::geometry);

Normaly validity is à pre-condition (src/algorithm/difference.cpp:426), so something is very wrong in the backtrace.

Did you happen to compile with the cmake option SFCGAL_CHECK_VALIDITY=OFF ?

@strk
Copy link

strk commented Aug 27, 2015

NOTICE: Too few points in geometry component at or near point 1 2

@vmora
Copy link
Contributor

vmora commented Aug 27, 2015

@str thanks, would you mind trying @robe2's request ?

@robe2
Copy link
Contributor Author

robe2 commented Aug 27, 2015

@vmora,

 SELECT ST_IsValid('POLYGON((1 2,1 2,1 2,1 2))'::geometry);
NOTICE:  Too few points in geometry component at or near point 1 2
 st_isvalid
------------
 f
(1 row)

Also verified same answer when backend is enabled:

 set postgis.backend=sfcgal;
SET
SELECT ST_IsValid('POLYGON((1 2,1 2,1 2,1 2))'::geometry);
NOTICE:  Too few points in geometry component at or near point 1 2
 st_isvalid
------------
 f
(1 row)

same answer as strk's

fa
Didn't even know about the SFCGAL_CHECK_VALIDITY OFF. So not intentionally if I did.

I think I didn't have the backend set to sfcgal, though I didn't think that would make a difference since this function is only provided by SFCGAL.

strk - does it crash for you too?

FWIW: vmora -- the ST_3DArea used to crash as well, but the 1.2 upgrade fixed that one.

Though interestingly it looks like its still trying to do an area check but at least throwing an error:

 SELECT ST_3DArea('POLYGON((1 2,1 2,1 2,1 2))'::geometry);
NOTICE:  During area_3d(A) :
NOTICE:    with A: POLYGON((1/1 2/1,1/1 2/1,1/1 2/1,1/1 2/1))
ERROR:  can't find plane for Polygon 'POLYGON((1.000 2.000,1.000 2.000,1.000 2.000,1.000 2.000))'

@vmora
Copy link
Contributor

vmora commented Aug 27, 2015

@robe2 I'm fine with the ST_IsValid answear, even if I should provide a nicer output msg when points are aligned.

The thing that bugs me is that the precondition in difference3D should fail and doesn't.

@strk is your sfcgal compiled in debug ? (I don't have one available right now).

@strk
Copy link

strk commented Aug 27, 2015

strk=# SELECT ST_3DDifference('POINT(-11.1111111 40)'::geometry,
'POLYGON((1 2,1 2,1 2,1 2))'::geometry) As result;
ERROR:  floating-point exception
DETAIL:  An invalid floating-point operation was signaled. This
probably means an out-of-range result or an invalid operation, such as
division by zero.

My SFCGAL build config:

cmake \
  -D CMAKE_CXX_COMPILER:FILEPATH=/usr/lib/ccache/g++ \
  -D CMAKE_CXX_FLAGS="-g -frounding-math" \
  -D CMAKE_BUILD_TYPE=Release\
  -D SFCGAL_BUILD_TESTS=True \
  -D SFCGAL_BUILD_BENCH=True \
  -D SFCGAL_WARNING_AS_ERROR=True \
  ${srcdir} \
  $@

@vmora vmora added the bug label Aug 27, 2015
@vmora
Copy link
Contributor

vmora commented Aug 27, 2015

So, confirmed it is.

@strk
Copy link

strk commented Aug 27, 2015

On Thu, Aug 27, 2015 at 02:16:09AM -0700, Vincent Mora wrote:

So, confirmed it is.

Which switch makes it a "debug" build ?

@vmora
Copy link
Contributor

vmora commented Aug 27, 2015

cmake -DCMAKE_BUILD_TYPE=Debug

@strk
Copy link

strk commented Aug 27, 2015

Ah, so "confirmed" it's the bug, not the fact that I'm using a debug build...

Evidently while my box catches the floating-point exception Regina's windows box crashes.
Does it sound ?

@vmora
Copy link
Contributor

vmora commented Aug 27, 2015

depends on the cgal version I guess (wild guess) because I get a CGAL assertion error here.

@mhugo
Copy link
Contributor

mhugo commented Aug 27, 2015

Adding this to IsValidTest reveals that our IsValid is wrong on this case

BOOST_AUTO_TEST_CASE( valid42 )
{
std::auto_ptr< Geometry > g( io::readWkt( "POLYGON((1 2,1 2,1 2,1 2))" ) );
Validity v = algorithm::isValid( *g );
BOOST_CHECK( !v );
}

@mhugo
Copy link
Contributor

mhugo commented Aug 27, 2015

@vmora didn't we have a sfcgal_is_valid() in postgis some times ago ?

@vmora
Copy link
Contributor

vmora commented Aug 27, 2015

@mhugo hugh ? What about the "can't find plane for Polygon" ?

@vmora
Copy link
Contributor

vmora commented Aug 27, 2015

Foud the problem: the polygon is a point, and the IsValid of SFCGAL (that apparently is not called by postgis) yields True with this guy.

I'm adding a test for this special case.

@robe2
Copy link
Contributor Author

robe2 commented Aug 27, 2015

I'm running CGAL 4.6.1 if that matters why I crash and you too don't. Could be just windows too cause I was testing on standard distributed PostgreSQL VC++ build (but all PostGIS parts are mingw compiled (including CGAL))

@vmora
Copy link
Contributor

vmora commented Aug 27, 2015

@robe2 I found the but, is valid was not catching the special case where polygon degenerates to a point (not valid).

Adding test + fix to master.

@vmora vmora closed this as completed in 3c994d5 Aug 27, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants