Opened 7 years ago

Closed 7 years ago

#1335 closed defect (fixed)

[PATCH] ST_AddPoint returns incorrect result on Linux

Reported by: realityexists Owned by: pramsey
Priority: critical Milestone: PostGIS 2.0.0
Component: postgis Version: trunk
Keywords: Cc: rouault

Description

Running PostGIS 2.0.0 r8251 on Ubuntu 11.04 with PostgreSQL 9.1.1.

SELECT ST_AsText(ST_AddPoint(
  ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326),
  ST_GeomFromText('POINT(10 10)', 4326),
  0));

returns "LINESTRING(10 10,20 20,20 20,40 40)"

PostGIS_FullVersion(): "POSTGIS="2.0.0SVN" GEOS="3.2.0-CAPI-1.6.0" PROJ="Rel. 4.7.1, 23 September 2009" GDAL="GDAL 1.6.3, released 2009/11/19" LIBXML="2.7.8" USE_STATS"

The latest Windows build (r8242) still returns the correct result ("LINESTRING(10 10,20 20,30 30,40 40)").

Attachments (1)

ticket_1335.patch (962 bytes) - added by rouault 7 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 7 years ago by pramsey

Correct answer here on OSX 10.6 x86_64. How many bits on your Linux system?

comment:2 Changed 7 years ago by realityexists

32

comment:3 Changed 7 years ago by darkblueb


32 bit Debian Linux, Intel, Postgres 9.1.1, Postgis some prev trunk (?)

db_20b=# SELECT ST_AsText(ST_AddPoint( db_20b(# ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326), db_20b(# ST_GeomFromText('POINT(10 10)', 4326), db_20b(# 0));

st_astext


LINESTRING(10 10,20 20,20 20,40 40)

(1 row)

================================================================ 32bit Debian Linux, Intel, Postgres 9.1.1, rebuilt trunk v8251

db_20b=# SELECT ST_AsText(ST_AddPoint( db_20b(# ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326), db_20b(# ST_GeomFromText('POINT(10 10)', 4326), db_20b(# 0));

st_astext


LINESTRING(10 10,20 20,20 20,40 20)

(1 row)

====================================================== 64bit Linux, Intel, Postgres 9.0.5, Postgis trunk v8251

db_20b=# SELECT ST_AsText(ST_AddPoint( db_20b(# ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326), db_20b(# ST_GeomFromText('POINT(10 10)', 4326), db_20b(# 0));

st_astext


LINESTRING(10 10,20 20,30 30,30 30)

(1 row)

comment:4 Changed 7 years ago by darkblueb

64bit Linux, AMD

psql (9.0.4)
Type "help" for help.

ct_test_09nov11=# select postgis_full_version();

 POSTGIS="1.5.3" GEOS="3.3.0-CAPI-1.7.0" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.7.8" USE_STATS
(1 row)

ct_test_09nov11=# select st_astext(st_addpoint(
ct_test_09nov11(#    st_geomfromtext( 'linestring(20 20,30 30,40 40)',4326),
ct_test_09nov11(#    st_geomfromtext( 'POINT(10 10)',4326),
ct_test_09nov11(#    0));
              st_astext              
-------------------------------------
 LINESTRING(10 10,20 20,30 30,40 40)
(1 row)

comment:5 Changed 7 years ago by darkblueb

two queries sequentially gives the same results; interspersing a function call in between gives two *different* results with the same build on the same architecture.

geocoder_ca=# SELECT ST_AsText(ST_AddPoint(
ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326),
ST_GeomFromText('POINT(10 10)', 4326),
0));
              st_astext              
-------------------------------------
 LINESTRING(10 10,20 20,20 20,40 20)
(1 row)

geocoder_ca=# select postgis_full_version();
geocoder_ca=# SELECT ST_AsText(ST_AddPoint(
ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326),
ST_GeomFromText('POINT(10 10)', 4326),
0));
              st_astext              
-------------------------------------
 LINESTRING(10 10,20 20,20 20,40 40)
(1 row)

comment:6 Changed 7 years ago by rouault

Cc: rouault added

The issue is an incorrect use of memcpy() instead of memmove() because of overlapping source/destination. So the result depends on implementations. I've fixed the addpoint and removepoint cases, but haven't done an extensive review of other potential similar errors.

Changed 7 years ago by rouault

Attachment: ticket_1335.patch added

comment:7 Changed 7 years ago by rouault

Summary: ST_AddPoint returns incorrect result on Linux[PATCH] ST_AddPoint returns incorrect result on Linux

comment:8 Changed 7 years ago by darkblueb

patch applied to trunk build here.. appears to work fine - thx EvenR ! --

db_20b=# SELECT ST_AsText(ST_AddPoint( ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326), ST_GeomFromText('POINT(10 10)', 4326), 0));

st_astext


LINESTRING(10 10,20 20,30 30,40 40)

(1 row)

db_20b=# select postgis_full_version(); ... db_20b=# SELECT ST_AsText(ST_AddPoint( ST_GeomFromText('LINESTRING(20 20,30 30,40 40)', 4326), ST_GeomFromText('POINT(10 10)', 4326), 0));

st_astext


LINESTRING(10 10,20 20,30 30,40 40)

(1 row)

comment:9 Changed 7 years ago by pramsey

Resolution: fixed
Status: newclosed

Thanks! r8257

Note: See TracTickets for help on using tickets.