Opened 6 years ago

Closed 3 years ago

#4157 closed defect (worksforme)

ST_3DIntersection segfaults on some geometries

Reported by: tilt Owned by: hmercier
Priority: critical Milestone: PostGIS SFCGAL
Component: sfcgal Version: master
Keywords: Cc:

Description

Postgres crashes with a segfault when using certain combinations, though it seems a rare occasion. It only seems to happen when at least one of the two geometries is a polyhedralsurfacez, with multiple surfaces.

Reproduced on:

"POSTGIS="2.5.0rc1dev r16693" [EXTENSION] PGSQL="100" GEOS="3.7.0beta2-CAPI-1.11.0 e7d54545" SFCGAL="1.3.5"

AND

POSTGIS="2.4.4 r16526" GEOS="3.7.0dev-CAPI-1.11.0 084542e5" SFCGAL="1.3.0"

Reproducable with:

WITH data as (
SELECT
ST_GeometryFromText(
'POLYGON Z ((
122395.299 489126.697 8.61546664325712,
122389.298 489128.73 8.55588025324629,
122391.489 489135.198 8.5526708028059,
122397.49 489133.165 8.61225719281685,
122395.299 489126.697 8.61546664325712))'
) as geoma,
ST_GeometryFromText(
'POLYHEDRALSURFACE Z (((
122390.998245685 489133.068537491 0,
122391.003145022 489133.066423547 0,
122391.003145022 489133.066423547 10,
122390.998245685 489133.068537491 10,
122390.998245685 489133.068537491 0
)),((
122391.003145022 489133.066423547 0,
122383.269575402 489114.842869866 0,
122383.269575402 489114.842869866 10,
122391.003145022 489133.066423547 10,
122391.003145022 489133.066423547 0
)))'
) as geomb
)
SELECT ST_3DIntersection(geoma, geomb)
FROM data

Attachments (1)

ticket_4157.patch.txt (1.6 KB ) - added by hmercier 6 years ago.
Patch to add a regression test if needed

Download all attachments as: .zip

Change History (11)

comment:1 by nicklas, 6 years ago

You mean ST_3DIntersection, right?

It says ST_3DIntersects in the header but ST_3DIntersection in the example

Last edited 6 years ago by nicklas (previous) (diff)

comment:2 by tilt, 6 years ago

Summary: ST_3DIntersects segfaults on some geometriesST_3DIntersection segfaults on some geometries

Thanks for spotting that Nicklas

comment:3 by hmercier, 6 years ago

Owner: changed from colivier to hmercier

Reproduced on a recent version

POSTGIS="3.0.0dev r16844" [EXTENSION] PGSQL="100" GEOS="3.6.2-CAPI-1.10.2 4d2925d6" SFCGAL="1.3.5" PROJ="Rel. 5.1.0, June 1st, 2018" LIBXML="2.9.4" LIBJSON="0.12.1"

Working on it …

by hmercier, 6 years ago

Attachment: ticket_4157.patch.txt added

Patch to add a regression test if needed

comment:6 by Algunenano, 6 years ago

Milestone: PostGIS 3.0.0PostGIS SFCGAL

comment:7 by komzpa, 5 years ago

Resolution: fixed
Status: newclosed

Works on Ubuntu 19.10:

14:35:48 [kom] > WITH data as (
SELECT
ST_GeometryFromText(
'POLYGON Z ((
122395.299 489126.697 8.61546664325712,
122389.298 489128.73 8.55588025324629,
122391.489 489135.198 8.5526708028059,
122397.49 489133.165 8.61225719281685,
122395.299 489126.697 8.61546664325712))'
) as geoma,
ST_GeometryFromText(
'POLYHEDRALSURFACE Z (((
122390.998245685 489133.068537491 0,
122391.003145022 489133.066423547 0,
122391.003145022 489133.066423547 10,
122390.998245685 489133.068537491 10,
122390.998245685 489133.068537491 0
)),((
122391.003145022 489133.066423547 0,
122383.269575402 489114.842869866 0,
122383.269575402 489114.842869866 10,
122391.003145022 489133.066423547 10,
122391.003145022 489133.066423547 0
)))'
) as geomb
)
SELECT ST_3DIntersection(geoma, geomb)
FROM data;
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                                                                                           st_3dintersection                                                                                                                                            │
├────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ 0105000080020000000102000080030000006ACBE10C70E1FD40C8880444B4DA1D4124705F66911C21403EDBFB0970E1FD40FC905444B4DA1D41B4200273901C2140A777D0F86FE1FD402AB12E46B4DA1D41C6C944D18A1C21400102000080020000006ACBE10C70E1FD40C8880444B4DA1D4124705F66911C2140B815F4515DE1FD40B2854C3BA9DA1D41D2AE31B6351C2140 │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(1 row)

Time: 3,128 ms

comment:8 by Algunenano, 5 years ago

Priority: mediumcritical
Resolution: fixed
Status: closedreopened

Tested with current trunk and sfcgal master and it's still crashing

Select postgis_full_version();
                                                                                     postgis_full_version           
                                                                           
--------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------
 POSTGIS="3.0.0alpha5dev r17774" [EXTENSION] PGSQL="120" GEOS="3.8.0dev-CAPI-1.11.0 " SFCGAL="1.3.7" PROJ="6.1.0" LI
BXML="2.9.9" LIBJSON="0.13.1" LIBPROTOBUF="1.3.1" WAGYU="0.4.3 (Internal)"
(1 row)

Coredump trace:

(gdb) bt
#0  __gmpn_copyi_core2 () at tmp-core2_copyi.s:136
#1  0x00007fc86389c9a6 in boost::multiprecision::backends::gmp_rational::gmp_rational (o=..., this=0x7fff2023a8a0) at /usr/include/boost/multiprecision/gmp.hpp:1844
#2  boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1>::number (e=..., this=0x7fff2023a8a0) at /usr/include/boost/multiprecision/number.hpp:52
#3  boost::array<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1>, 3ul>::array (this=0x7fff2023a8a0) at /usr/include/boost/array.hpp:61
#4  0x00007fc86389d71c in CGAL::VectorC3<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> > >::VectorC3 (this=0x7fff2023a8a0)
    at /usr/include/CGAL/Cartesian/Vector_3.h:36
#5  CGAL::Vector_3<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> > >::Vector_3 (this=0x7fff2023a8a0)
    at /usr/include/CGAL/Vector_3.h:43
#6  CGAL::PointC3<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> > >::PointC3 (this=0x7fff2023a8a0)
    at /usr/include/CGAL/Cartesian/Point_3.h:34
#7  CGAL::Point_3<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> > >::Point_3 (this=0x7fff2023a8a0)
    at /usr/include/CGAL/Point_3.h:40
#8  CGAL::make_array<CGAL::Point_3<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> > > > (b2=..., b1=...)
    at /usr/include/CGAL/array.h:113
#9  CGAL::SegmentC3<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> > >::SegmentC3 (ep=..., sp=..., this=0x7fff2023a8a0)
    at /usr/include/CGAL/Cartesian/Segment_3.h:54
#10 CGAL::CommonKernelFunctors::Construct_segment_3<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> > >::operator() (
    this=0x5611bb8c7520, q=..., p=...) at /usr/include/CGAL/Kernel/function_objects.h:2254
#11 CGAL::Lazy_rep_3<CGAL::Segment_3<CGAL::Simple_cartesian<CGAL::Interval_nt<false> > >, CGAL::Segment_3<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> > >, CGAL::CommonKernelFunctors::Construct_segment_3<CGAL::Simple_cartesian<CGAL::Interval_nt<false> > >, CGAL::CommonKernelFunctors::Construct_segment_3<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> > >, CGAL::Cartesian_converter<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> >, CGAL::Simple_cartesian<CGAL::Interval_nt<false> >, CGAL::NT_converter<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1>, CGAL::Interval_nt<false> > >, CGAL::Return_base_tag, CGAL::Point_3<CGAL::Epeck>, CGAL::Point_3<CGAL::Epeck> >::update_exact (this=0x5611bb8c7520) at /usr/include/CGAL/Lazy.h:455
#12 0x00007fc86392c9ca in CGAL::Lazy_rep<CGAL::Segment_3<CGAL::Simple_cartesian<CGAL::Interval_nt<false> > >, CGAL::Segment_3<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> > >, CGAL::Cartesian_converter<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> >, CGAL::Simple_cartesian<CGAL::Interval_nt<false> >, CGAL::NT_converter<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1>, CGAL::Interval_nt<false> > > >::exact (
    this=0x5611bb8c7520) at /usr/include/CGAL/Lazy.h:273
#13 CGAL::Lazy<CGAL::Segment_3<CGAL::Simple_cartesian<CGAL::Interval_nt<false> > >, CGAL::Segment_3<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> > >, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1>, CGAL::Cartesian_converter<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> >, CGAL::Simple_cartesian<CGAL::Interval_nt<false> >, CGAL::NT_converter<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1>, CGAL::Interval_nt<false> > > >::exact (this=0x7fff2023aa20) at /usr/include/CGAL/Lazy.h:792
#14 CGAL::exact<CGAL::Segment_3<CGAL::Simple_cartesian<CGAL::Interval_nt<false> > >, CGAL::Segment_3<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> > >, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1>, CGAL::Cartesian_converter<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> >, CGAL::Simple_cartesian<CGAL::Interval_nt<false> >, CGAL::NT_converter<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1>, CGAL::Interval_nt<false> > > > (l=...) at /usr/include/CGAL/Lazy.h:92
#15 CGAL::Lazy_construction_variant<CGAL::Epeck, CGAL::CommonKernelFunctors::Intersect_3<CGAL::Simple_cartesian<CGAL::Interval_nt<false> > >, CGAL::CommonKernelFunctors::Intersect_3<CGAL::Simple_cartesian<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, (boost::multiprecision::expression_template_option)1> > > >::operator()<CGAL::Segment_3<CGAL::Epeck>, CGAL::Segment_3<CGAL::Epeck> > (this=this@entry=0x7fff2023abb8, l1=..., l2=...)
    at /usr/include/CGAL/Lazy.h:1593
#16 0x00007fc863a817d6 in CGAL::intersection<CGAL::Epeck> (b=..., a=...) at /usr/include/CGAL/Intersections_3/Segment_3_Segment_3.h:31
#17 SFCGAL::algorithm::selfIntersectsImpl<3> (line=...) at /tmp/yaourt-tmp-raul/aur-sfcgal-git/src/sfcgal/src/algorithm/intersects.cpp:473
#18 0x00007fc863a70296 in SFCGAL::algorithm::selfIntersects3D (l=...) at /tmp/yaourt-tmp-raul/aur-sfcgal-git/src/sfcgal/src/algorithm/intersects.cpp:507
#19 0x00007fc863a82d8a in SFCGAL::algorithm::isValid (p=..., toleranceAbs=@0x7fff2023b230: 1.0000000000000001e-09) at /usr/include/c++/9.1.0/bits/stl_vector.h:1058
#20 0x00007fc863a85a0e in SFCGAL::algorithm::isValid (g=..., toleranceAbs=@0x7fff2023b230: 1.0000000000000001e-09) at /tmp/yaourt-tmp-raul/aur-sfcgal-git/src/sfcgal/src/algorithm/isValid.cpp:525
#21 0x00007fc863a85be5 in SFCGAL::SFCGAL_ASSERT_GEOMETRY_VALIDITY_ (g=..., ctxt="") at /tmp/yaourt-tmp-raul/aur-sfcgal-git/src/sfcgal/src/algorithm/isValid.cpp:63
#22 0x00007fc863a85c58 in SFCGAL::SFCGAL_ASSERT_GEOMETRY_VALIDITY (g=...) at /usr/include/c++/9.1.0/bits/char_traits.h:300
#23 0x00007fc863a85f09 in SFCGAL::SFCGAL_ASSERT_GEOMETRY_VALIDITY_3D (g=...) at /tmp/yaourt-tmp-raul/aur-sfcgal-git/src/sfcgal/src/algorithm/isValid.cpp:108

comment:9 by cege, 3 years ago

Has there been any resolution for this? I'm getting the same problem see ticket: https://trac.osgeo.org/postgis/ticket/5020 for sample data and details

comment:10 by robe, 3 years ago

Resolution: worksforme
Status: reopenedclosed

I just tried the sample query on this ticket again and it works fine on my SFCGAL 1.4.0 install. So reclosing this. As mentioned on #5020 try doing an upgrade.

Note: See TracTickets for help on using tickets.