libgeos / geos

Geometry Engine, Open Source
https://libgeos.org
GNU Lesser General Public License v2.1
1.1k stars 339 forks source link

Segmentation fault in CGAlgorithmsDD.cpp #1072

Open gabe-sherman opened 1 month ago

gabe-sherman commented 1 month ago

A segmentation fault occurs in the below program. This behavior occurs at line 90 in CGAlgorithmsDD.cpp

#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <geos_c.h>

static void handler(const char *fmt, ...){
    exit(0);
}

int main(int argc, char *argv[])
{
    initGEOS(handler, handler);
    GEOSGeometry *v0 = GEOSGeomFromWKT("LINESTRING(7777777777777777770 7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777770 1, 1 7 1,-2 1 2)");
    GEOSGeometry* v1 = GEOSSingleSidedBuffer(v0, 1.0, 64, 1, 1.0, 1);
    GEOSGeometry *v2 = GEOSMinimumBoundingCircle(v1, NULL, NULL);
    return 0;
}

Test Environment

Ubuntu 22.04, 64bit

How to trigger

./filename

Version

Latest: c8b889be9e8fa22de8a34bea50fec3bb073f6898

Address Sanitizer Output

/home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/precision/CommonBits.cpp:74:33: runtime error: 7.77778e+300 is outside the range of representable values of type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/precision/CommonBits.cpp:74:33 in 
/home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/algorithm/ConvexHull.cpp:66:45: runtime error: upcast of misaligned address 0xbebebebebebebebe for type 'geos::geom::Coordinate', which requires 8 byte alignment
0xbebebebebebebebe: note: pointer points here
<memory cannot be printed>
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/algorithm/ConvexHull.cpp:66:45 in 
/home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/algorithm/ConvexHull.cpp:66:45: runtime error: reference binding to misaligned address 0xbebebebebebebebe for type 'const geom::CoordinateXY', which requires 8 byte alignment
0xbebebebebebebebe: note: pointer points here
<memory cannot be printed>
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/algorithm/ConvexHull.cpp:66:45 in 
AddressSanitizer:DEADLYSIGNAL
=================================================================
==346778==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x555555cf1c14 bp 0x0c227fff83e1 sp 0x7fffffffcc30 T0)
==346778==The signal is caused by a READ memory access.
==346778==Hint: this fault was caused by a dereference of a high value address (see register values below).  Disassemble the provided pc to learn which register was used.
    #0 0x555555cf1c14 in geos::algorithm::CGAlgorithmsDD::orientationIndex(geos::geom::CoordinateXY const&, geos::geom::CoordinateXY const&, geos::geom::CoordinateXY const&) /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/algorithm/CGAlgorithmsDD.cpp:90:44
    #1 0x555555cfbfde in geos::algorithm::(anonymous namespace)::RadiallyLessThen::polarCompare(geos::geom::Coordinate const*, geos::geom::Coordinate const*, geos::geom::Coordinate const*) /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/algorithm/ConvexHull.cpp:66:22
    #2 0x555555cfc56a in geos::algorithm::(anonymous namespace)::RadiallyLessThen::operator()(geos::geom::Coordinate const*, geos::geom::Coordinate const*) /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/algorithm/ConvexHull.cpp:107:17
    #3 0x555555cfc56a in bool __gnu_cxx::__ops::_Iter_comp_iter<geos::algorithm::(anonymous namespace)::RadiallyLessThen>::operator()<__gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > > >(__gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/predefined_ops.h:158:23
    #4 0x555555cfc56a in __gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > > std::__unguarded_partition<__gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__ops::_Iter_comp_iter<geos::algorithm::(anonymous namespace)::RadiallyLessThen> >(__gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__ops::_Iter_comp_iter<geos::algorithm::(anonymous namespace)::RadiallyLessThen>) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_algo.h:1884:11
    #5 0x555555cfae95 in __gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > > std::__unguarded_partition_pivot<__gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__ops::_Iter_comp_iter<geos::algorithm::(anonymous namespace)::RadiallyLessThen> >(__gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__ops::_Iter_comp_iter<geos::algorithm::(anonymous namespace)::RadiallyLessThen>) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_algo.h:1906:14
    #6 0x555555cfaa00 in void std::__introsort_loop<__gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, long, __gnu_cxx::__ops::_Iter_comp_iter<geos::algorithm::(anonymous namespace)::RadiallyLessThen> >(__gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, long, __gnu_cxx::__ops::_Iter_comp_iter<geos::algorithm::(anonymous namespace)::RadiallyLessThen>) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_algo.h:1938:6
    #7 0x555555cf9564 in void std::__sort<__gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__ops::_Iter_comp_iter<geos::algorithm::(anonymous namespace)::RadiallyLessThen> >(__gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__ops::_Iter_comp_iter<geos::algorithm::(anonymous namespace)::RadiallyLessThen>) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_algo.h:1954:4
    #8 0x555555cf9564 in void std::sort<__gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, geos::algorithm::(anonymous namespace)::RadiallyLessThen>(__gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, __gnu_cxx::__normal_iterator<geos::geom::Coordinate const**, std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> > >, geos::algorithm::(anonymous namespace)::RadiallyLessThen) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_algo.h:4875:7
    #9 0x555555cf9564 in geos::algorithm::ConvexHull::preSort(std::vector<geos::geom::Coordinate const*, std::allocator<geos::geom::Coordinate const*> >&) /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/algorithm/ConvexHull.cpp:289:5
    #10 0x555555cf8307 in geos::algorithm::ConvexHull::getConvexHull() /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/algorithm/ConvexHull.cpp:258:5
    #11 0x555555a61fbd in geos::geom::Geometry::convexHull() const /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/geom/Geometry.cpp:512:29
    #12 0x5555559de8c0 in geos::algorithm::MinimumBoundingCircle::computeCirclePoints() /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/algorithm/MinimumBoundingCircle.cpp:220:49
    #13 0x5555559dbd5f in geos::algorithm::MinimumBoundingCircle::compute() /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/algorithm/MinimumBoundingCircle.cpp:196:5
    #14 0x5555559db629 in geos::algorithm::MinimumBoundingCircle::getCircle() /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/algorithm/MinimumBoundingCircle.cpp:51:5
    #15 0x55555596fef8 in GEOSMinimumBoundingCircle_r::$_99::operator()() const /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/capi/geos_ts_c.cpp:1989:48
    #16 0x55555596fef8 in _Z7executeIZ27GEOSMinimumBoundingCircle_rE4$_99LDn0EEDTclfp0_EEP20GEOSContextHandle_HSOT_ /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/capi/geos_ts_c.cpp:430:16
    #17 0x55555596fc62 in GEOSMinimumBoundingCircle_r /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/capi/geos_ts_c.cpp:1985:16
    #18 0x555555935178 in main /home/gabesherman/harness_test/AutoHarn-Results/geos/autoharn-04/reproducer.c:16:24
    #19 0x7ffff7029d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #20 0x7ffff7029e3f in __libc_start_main csu/../csu/libc-start.c:392:3
    #21 0x555555877574 in _start (/home/gabesherman/harness_test/AutoHarn-Results/geos/autoharn-04/reproducer+0x323574) (BuildId: d056de2ad3c813468785120495fa32ec7d9bfc44)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/gabesherman/harness_test/AutoHarn-Evaluation/geos/lib_asan/src/algorithm/CGAlgorithmsDD.cpp:90:44 in geos::algorithm::CGAlgorithmsDD::orientationIndex(geos::geom::CoordinateXY const&, geos::geom::CoordinateXY const&, geos::geom::CoordinateXY const&)
==346778==ABORTING