Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#219 closed defect (fixed)

This geometry causes buffer(?, 0) to crash the PostGresql server

Reported by: robe Owned by: strk
Priority: major Milestone: 3.0.4
Component: Default Version: 3.0.3
Severity: Unassigned Keywords:
Cc: mbdavis@…

Description (last modified by mloskot)

This was submitted to PostGIS -- and we have confirmed this to be an issue in 3.0.3 and 3.1.0 SVN of GEOS with newer installs of PostGIS and believe its a GEOS bug and not a PostGIS one. Refer to http://code.google.com/p/postgis/issues/detail?id=81

What steps will reproduce the problem?

  1. Run the attached script

What is the expected output? What do you see instead?

server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
connection to server was lost

What version of the product are you using? On what operating system?

psql 8.3.5
postgis_version: 1.3 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
postgis_geos_version: 3.0.1-CAPI-1.4.2
Fedora 10

Please provide any additional information below.

The following is written to the log file:

bufferOriginalPrecision failed (TopologyException: unable to assign hole to a shell), trying with reduced precision recomputing with precision scale factor = 1e+09
Scaler: offsetX,Y: 0,0 scaleFactor: 1e+09
 dstahlke svdev [local] SELECT:
../../source/headers/geos/noding/SegmentString.h:175: void geos::noding::SegmentString::testInvariant() const: Assertion `pts->size() > 1' failed.
LOG:  server process (PID 863) was terminated by signal 6: Aborted
LOG:  terminating any other active server processes
LOG:  all server processes terminated; reinitializing
LOG:  database system was interrupted; last known up at 2008-12-05 14:16:19 AKST
LOG:  database system was not properly shut down; automatic recovery in progress
LOG:  record with zero length at 0/3C5BC340
LOG:  redo is not required
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started

Attachments (3)

geos-bug.sql (13.5 KB ) - added by robe 15 years ago.
bug219.xml (13.7 KB ) - added by strk 15 years ago.
XML test file
bug219.sql (25.6 KB ) - added by strk 15 years ago.
SQL file with input/output geoms

Download all attachments as: .zip

Change History (11)

by robe, 15 years ago

Attachment: geos-bug.sql added

comment:1 by pramsey, 15 years ago

Milestone: 3.0.4
Owner: changed from geos-devel@… to pramsey
Version: 3.0.3

comment:2 by mloskot, 15 years ago

Description: modified (diff)

comment:3 by pramsey, 15 years ago

OK, I can reproduce the crash here. The problem is that the fifth component of the MULTIPOLYGON is a zero-area (within floating point tolerance) square. If I re-build the multipolygon without that element, the crash goes away. Here's what I did...

 pramsey=# create table foo as select geometryn(geom,generate_series(1,6)) from badbuffer;
 SELECT 
 pramsey=# select count(*) from foo;
 count 
 -------
     6
 (1 row)
 pramsey=# delete from foo where area(geometryn) = 0;
 DELETE 1
 pramsey=# create table foo2 as select collect(geometryn) as geom from foo;
 SELECT
 pramsey=# select count(*) from foo2;
 count 
 -------
      1
 (1 row)
 pramsey=# select geometrytype(geom) from foo2;
  geometrytype  
 --------------
  MULTIPOLYGON
 (1 row)
 pramsey=# select isvalid(buffer(geom,0)) from foo2;
  isvalid 
 ---------
  t
 (1 row)

So the work-around is there, if you need it, and we know pretty precisely where the problem is to go and fix it.

comment:4 by strk, 15 years ago

Owner: changed from pramsey to strk
Status: newassigned

Confirmed, can reproduce with a GEOS XML test. Working on it.

comment:5 by strk, 15 years ago

Resolution: fixed
Status: assignedclosed

Fixed as of revision 2481.

comment:6 by strk, 15 years ago

Note: the input multipolygon is invalid: NOTICE: Self-intersection at or near point -164.805 63.0918

That said, I don't think it is sane to put it into an XML tester as we can't really pretend the non-segfaulting result is the correct one (and it isn't, in that it trims out the offending polygon)

comment:7 by pramsey, 15 years ago

Right, the reason people are running buffer(,0) is to "clean" invalid polygons. What we need is to start building an API specifically for that purpose that expects, nay, welcomes invalidity.

by strk, 15 years ago

Attachment: bug219.xml added

XML test file

by strk, 15 years ago

Attachment: bug219.sql added

SQL file with input/output geoms

comment:8 by strk, 15 years ago

Cc: mbdavis@… added

Not sure the result I'm seeing we can accept as an "expected" cleanup output.

I attach an XML tester (expecting empty geom, just for fun) and an SQL file that creates a bug219_xml table with fields 'a' as input geometry and 'obtained' as the result of buffer(0).

Martin, your thoughts on this ? Is it sane to use Buffer(0) to cleanup geoms, and is what you get on the attached geometry an expected cleanup ?

Note: See TracTickets for help on using tickets.