osmcode / osmcoastline

Extracts coastline data from OpenStreetMap planet file.
https://osmcode.org/osmcoastline/
GNU General Public License v3.0
109 stars 14 forks source link

segfault in GEOS crashes process #2

Closed springmeyer closed 12 years ago

springmeyer commented 12 years ago

I'm not positive, but this looks like a geos bug. If so, apologies creating here. But, I figured it would be good to get your feedback @joto before proceeding.

Basically, playing around with this cool tool and hit a crash while processing invalid geoms. The output leading up to it was:

There are 2 nodes where the coastline is not closed.
There are 455418 coastline rings (446662 from a single way and 8756 from multiple ways).
Done (about 17 minutes).
VmPeak:  1265188 kB
VmSize:  1076288 kB
-------------------------------------------------------------------------------
Reading nodes (2nd pass through input file)...
Done (about 43 minutes).
VmPeak:  2548148 kB
VmSize:  2482608 kB
-------------------------------------------------------------------------------
Create and output polygons...
Warning 1: Self-intersection at or near point -93.6495 61.8763
Warning 1: Self-intersection at or near point -63.519 65.5395
Warning 1: Self-intersection at or near point 23.6221 37.9386
ERROR 1: IllegalArgumentException: point array must contain 0 or >1 elements

ERROR 1: IllegalArgumentException: point array must contain 0 or >1 elements

Then I re-ran the process with osmcoastline compiled with -g -ggdb -O0 and see:

Thread 1 (Thread 0x7ffff7fd3760 (LWP 16728)):
#0  0x00007ffff2284249 in geos::operation::valid::IsValidOp::checkValid(geos::geom::Geometry const*) () from /usr/lib/libgeos-3.2.2.so
#1  0x00007ffff2284539 in geos::operation::valid::IsValidOp::checkValid() () from /usr/lib/libgeos-3.2.2.so
#2  0x00007ffff2284559 in geos::operation::valid::IsValidOp::isValid() () from /usr/lib/libgeos-3.2.2.so
#3  0x00007ffff693f942 in GEOSisValidReason_r () from /usr/lib/libgeos_c.so.1
#4  0x00000000004285d4 in LayerRings::add (this=0x672b00, polygon=0x8546b9b0, id=154820504, nways=1, npoints=1, layer_error_points=0x656f30)
    at output_layers.cpp:177
#5  0x0000000000405c6e in output_rings (coastline_rings=..., output=...) at osmcoastline.cpp:214
#6  0x00000000004065de in main (argc=3, argv=0x7fffffffe6c8) at osmcoastline.cpp:313

On the hunch that the id above is the actual osm_id I then tried:

curl http://www.openstreetmap.org/api/0.6/way/15518929 > 15518929.osm
root@water:~# gdb --args osmcoastline/osmcoastline 15518929.osm  coastline                                                                                     
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /root/osmcoastline/osmcoastline...done.
(gdb) r
Starting program: /root/osmcoastline/osmcoastline 15518929.osm coastline
[Thread debugging using libthread_db enabled]
-------------------------------------------------------------------------------
Reading ways (1st pass through input file)...
There are 0 nodes where the coastline is not closed.
There are 0 coastline rings (0 from a single way and 0 from multiple ways).
Done (about 0 minutes).
VmPeak:   170488 kB
VmSize:   170484 kB
-------------------------------------------------------------------------------
Reading nodes (2nd pass through input file)...
Done (about 0 minutes).
VmPeak:   170488 kB
VmSize:   170484 kB
-------------------------------------------------------------------------------
Create and output polygons...

Program received signal SIGSEGV, Segmentation fault.
0x0000000000405f42 in output_polygons (coastline_rings=..., output=...) at osmcoastline.cpp:245
245         assert(mega_multipolygon->getGeometryType() == wkbMultiPolygon);
(gdb) bt
#0  0x0000000000405f42 in output_polygons (coastline_rings=..., output=...) at osmcoastline.cpp:245
#1  0x000000000040662c in main (argc=3, argv=0x7fffffffe6d8) at osmcoastline.cpp:316
springmeyer commented 12 years ago

Upgrading to geos trunk it now works (confirming to me this is a geos bug):

Reading ways (1st pass through input file)...                                                                                                                 
There are 2 nodes where the coastline is not closed.                                                                                                          
There are 455418 coastline rings (446662 from a single way and 8756 from multiple ways).                                                                      
Done (about 17 minutes).                                                                                                                                      │
VmPeak:  1279684 kB                                                                                                                                           │
VmSize:  1094764 kB                                                                                                                                           │
-------------------------------------------------------------------------------                                                                               │
Reading nodes (2nd pass through input file)...                                                                                                                │
Done (about 43 minutes).                                                                                                                                      │
VmPeak:  2550144 kB                                                                                                                                           │
VmSize:  2484604 kB                                                                                                                                           │
-------------------------------------------------------------------------------                                                                               │
Create and output polygons...                                                                                                                                 │
Warning 1: Self-intersection at or near point -93.649499999999989 61.876250000000006                                                                          │
Warning 1: Self-intersection at or near point -63.518999999999991 65.539500000000004                                                                          │
Warning 1: Self-intersection at or near point 23.622058972617769 37.938603015817954                                                                           │
ERROR 1: IllegalArgumentException: point array must contain 0 or >1 elements                                                                                  │
                                                                                                                                                              │
ERROR 1: IllegalArgumentException: point array must contain 0 or >1 elements                                                                                  │
                                                                                                                                                              │
Warning 1: organizePolygons() received an unexpected geometry.                                                                                                │
Either a polygon with interior rings, or a polygon with less than 4 points,                                                                                   │
or a non-Polygon geometry.  Return arguments as a collection.                                                                                                 │
Done (about 5 minutes).                                                                                                                                       │
VmPeak:  3397232 kB                                                                                                                                           │
VmSize:  3203628 kB                                                                                                                                           │
joto commented 12 years ago

I bumped into this problem also and have a workaround before calling geos. I have not released that fix yet, because I have to test it some more.