]> granicus.if.org Git - postgis/commitdiff
Fixed out-of-bound condition in ptarray_substring during copy of
authorSandro Santilli <strk@keybit.net>
Wed, 18 Jan 2006 10:19:11 +0000 (10:19 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 18 Jan 2006 10:19:11 +0000 (10:19 +0000)
unaltered points.
Added regress test for the case (postgis-devel/2006-January/001951.html)

git-svn-id: http://svn.osgeo.org/postgis/trunk@2284 b70326c6-7e19-0410-871a-916f4a2858ee

CHANGES
lwgeom/ptarray.c
regress/regress_lrs.sql
regress/regress_lrs_expected

diff --git a/CHANGES b/CHANGES
index 718a5ac8ad33ff40f727bfd93db58ffc225cb2a7..864f46d4da9ffec361316c6efdfbe1d94df639c3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,7 @@ PostGIS 1.1.1CVS
        - BUGFIX in line_locate_point()
        - Fixed handling of postgresql paths
        - Fixed a premature exit in postgis_restore.pl 
+       - Fixed memory bug in line_substring()
 
 PostGIS 1.1.0
 2005/12/21
index 7bd5de9f017307d309804e09349b47726f1118cd..d1672d5a0029a78c81d77ea8119ff17f063ac4e3 100644 (file)
@@ -437,6 +437,9 @@ ptarray_compute_box3d_p(const POINTARRAY *pa, BOX3D *result)
        return 1;
 }
 
+/*
+ * TODO: implement point interpolation
+ */
 POINTARRAY *
 ptarray_substring(POINTARRAY *ipa, double from, double to)
 {
@@ -487,7 +490,7 @@ ptarray_substring(POINTARRAY *ipa, double from, double to)
                 * so far. create a new point some distance down the current
                 * segment.
                 */
-               if ( state == 0 )
+               if ( state == 0 ) /* before */
                {
                        if ( from < tlength + slength ) {
                                dseg = (from - tlength) / slength;
@@ -500,8 +503,9 @@ ptarray_substring(POINTARRAY *ipa, double from, double to)
                        }
                }
 
-               if ( state == 1 )
+               if ( state == 1 ) /* inside */
                {
+                       /* Need interpolation */
                        if ( to < tlength + slength ) {
                                dseg = (to - tlength) / slength;
                                pt.x = (p1.x) + ((p2.x - p1.x) * dseg);
@@ -510,8 +514,14 @@ ptarray_substring(POINTARRAY *ipa, double from, double to)
                                memcpy(optsptr, &pt, ptsize);
                                optsptr+=ptsize;
                                nopts++; break;
-                       } else {
-                               memcpy(optsptr, &p2, ptsize);
+                       }
+
+                       /* Copy verbatim point */
+                       else {
+                               pt.x = p2.x;
+                               pt.y = p2.y;
+                               pt.z = 0; pt.m = 0;
+                               memcpy(optsptr, &pt, ptsize);
                                optsptr+=ptsize;
                                nopts++;
                        }
index 8a609793d6ea65ce3b80934a559401e668ad7276..c9b04a7782948c4b1afd1fca72ac81bfe39f3108 100644 (file)
@@ -30,3 +30,6 @@ SELECT 'line_locate_point', line_locate_point('LINESTRING(709243.393033887 16396
 --- postgis-users/2006-January/010613.html
 select 'line_locate_point', line_locate_point(geomfromtext('LINESTRING(-1953743.873 471070.784,-1953735.105 471075.419,-1953720.034 471081.649)', 6269), geomfromtext('POINT(-1953720.034 471081.649)', 6269));
 select 'line_locate_point', line_locate_point(geomfromtext('LINESTRING(-1953743.873 471070.784,-1953735.105 471075.419,-1953720.034 471081.649)', 6269), geomfromtext('POINT(-1953743.873 471070.784)', 6269));
+
+--- postgis-devel/2006-January/001951.html
+select 'line_substring', asewkt(line_substring(geomfromewkt('SRID=4326;LINESTRING(0 0 0 0, 1 1 1 1, 2 2 2 2, 3 3 3 3, 4 4 4 4)'), 0.5, 0.8));
index fea59926c01a4c634b55a00dfab92e3b0fe1e018..f7442f9639fd6bb6f7baeeaf1e8f985b69eaac5a 100644 (file)
@@ -18,3 +18,4 @@ LINEZM_6|POINT(9.5 0.5 0.5 2)
 line_locate_point|0.528602749909894
 line_locate_point|1
 line_locate_point|0
+line_substring|SRID=4326;LINESTRING(2 2 0 0,3 3 0 0,3.2 3.2 0 0)