[postgis-tickets] r17717 - Guard against memory access when npoints of pointarray == 0

Paul Ramsey pramsey at cleverelephant.ca
Thu Aug 15 10:01:47 PDT 2019


Author: pramsey
Date: 2019-08-15 10:01:47 -0700 (Thu, 15 Aug 2019)
New Revision: 17717

Modified:
   branches/2.5/liblwgeom/g_serialized.c
   branches/2.5/raster/test/regress/bug_test_car5.sql
   branches/2.5/raster/test/regress/rt_mapalgebra.sql
Log:
Guard against memory access when npoints of pointarray == 0


Modified: branches/2.5/liblwgeom/g_serialized.c
===================================================================
--- branches/2.5/liblwgeom/g_serialized.c	2019-08-15 17:00:19 UTC (rev 17716)
+++ branches/2.5/liblwgeom/g_serialized.c	2019-08-15 17:01:47 UTC (rev 17717)
@@ -948,7 +948,8 @@
 			lwerror("Dimensions mismatch in lwpoly");
 
 		pasize = pa->npoints * ptsize;
-		memcpy(loc, getPoint_internal(pa, 0), pasize);
+		if ( pa->npoints > 0 )
+			memcpy(loc, getPoint_internal(pa, 0), pasize);
 		loc += pasize;
 	}
 	return (size_t)(loc - buf);

Modified: branches/2.5/raster/test/regress/bug_test_car5.sql
===================================================================
--- branches/2.5/raster/test/regress/bug_test_car5.sql	2019-08-15 17:00:19 UTC (rev 17716)
+++ branches/2.5/raster/test/regress/bug_test_car5.sql	2019-08-15 17:01:47 UTC (rev 17717)
@@ -36,10 +36,11 @@
 --
 -- Raster: 5 x 5 pixels, 3 bands, PT_8BUI pixel type, nodata = 0
 --
-INSERT INTO car5 (rid,rast) VALUES (1, ('01000003009A9999999999A93F9A9999999999A9BF000000E02B274A41000000007719564100000000000000000000000000000000FFFFFFFF050005000400FDFEFDFEFEFDFEFEFDF9FAFEFEFCF9FBFDFEFEFDFCFAFEFEFE04004E627AADD16076B4F9FE6370A9F5FE59637AB0E54F58617087040046566487A1506CA2E3FA5A6CAFFBFE4D566DA4CB3E454C5665')::raster );
-INSERT INTO car5 (rid,rast) VALUES (2, ('01000003009A9999999999A93F9A9999999999A9BF000000E02B274A41000000007719564100000000000000000000000000000000FFFFFFFF050005000400FDFEFDFEFEFDFEFEFDF9FAFEFEFCF9FBFDFEFEFDFCFAFEFEFE04004E627AADD16076B4F9FE6370A9F5FE59637AB0E54F58617087040046566487A1506CA2E3FA5A6CAFFBFE4D566DA4CB3E454C5665')::raster );
-INSERT INTO car5 (rid,rast) VALUES (3, ('01000003009A9999999999A93F9A9999999999A9BF000000E02B274A41000000007719564100000000000000000000000000000000FFFFFFFF050005000400FDFEFDFEFEFDFEFEFDF9FAFEFEFCF9FBFDFEFEFDFCFAFEFEFE04004E627AADD16076B4F9FE6370A9F5FE59637AB0E54F58617087040046566487A1506CA2E3FA5A6CAFFBFE4D566DA4CB3E454C5665')::raster );
 
+INSERT INTO car5 (rid,rast) VALUES (1, ('01000003009A9999999999A93F9A9999999999A9BF000000E02B274A4100000000771956410000000000000000000000000000000000000000050005000400FDFEFDFEFEFDFEFEFDF9FAFEFEFCF9FBFDFEFEFDFCFAFEFEFE04004E627AADD16076B4F9FE6370A9F5FE59637AB0E54F58617087040046566487A1506CA2E3FA5A6CAFFBFE4D566DA4CB3E454C5665')::raster );
+INSERT INTO car5 (rid,rast) VALUES (2, ('01000003009A9999999999A93F9A9999999999A9BF000000E02B274A4100000000771956410000000000000000000000000000000000000000050005000400FDFEFDFEFEFDFEFEFDF9FAFEFEFCF9FBFDFEFEFDFCFAFEFEFE04004E627AADD16076B4F9FE6370A9F5FE59637AB0E54F58617087040046566487A1506CA2E3FA5A6CAFFBFE4D566DA4CB3E454C5665')::raster );
+INSERT INTO car5 (rid,rast) VALUES (3, ('01000003009A9999999999A93F9A9999999999A9BF000000E02B274A4100000000771956410000000000000000000000000000000000000000050005000400FDFEFDFEFEFDFEFEFDF9FAFEFEFCF9FBFDFEFEFDFCFAFEFEFE04004E627AADD16076B4F9FE6370A9F5FE59637AB0E54F58617087040046566487A1506CA2E3FA5A6CAFFBFE4D566DA4CB3E454C5665')::raster );
+
 -- Run test
 SELECT rid, st_width(rast), st_height(rast), st_bandpixeltype(rast,1), st_bandpixeltype(rast,2), st_bandpixeltype(rast,3) FROM car5;
 

Modified: branches/2.5/raster/test/regress/rt_mapalgebra.sql
===================================================================
--- branches/2.5/raster/test/regress/rt_mapalgebra.sql	2019-08-15 17:00:19 UTC (rev 17716)
+++ branches/2.5/raster/test/regress/rt_mapalgebra.sql	2019-08-15 17:01:47 UTC (rev 17717)
@@ -88,6 +88,7 @@
 		) AS rast
 	FROM raster_nmapalgebra_in
 	WHERE rid IN (3,4)
+	OFFSET 0
 )
 SELECT
 	rid,
@@ -130,6 +131,7 @@
 			AND t2.rid BETWEEN 10 AND 18
 			AND ST_Intersects(t1.rast, t2.rast)
 		GROUP BY t1.rid, t1.rast
+		OFFSET 0
 	)
 	SELECT
 		rid,
@@ -156,6 +158,7 @@
 			AND t2.rid BETWEEN 10 AND 18
 			AND ST_Intersects(t1.rast, t2.rast)
 		GROUP BY t1.rid, t1.rast
+		OFFSET 0
 	)
 	SELECT
 		rid,
@@ -183,6 +186,7 @@
 			AND t2.rid BETWEEN 10 AND 18
 			AND ST_Intersects(t1.rast, t2.rast)
 		GROUP BY t1.rid, t1.rast
+		OFFSET 0
 	)
 	SELECT
 		rid,
@@ -205,6 +209,7 @@
 			AND t2.rid BETWEEN 10 AND 18
 		WHERE t1.rid = 10
 		GROUP BY t1.rid
+		OFFSET 0
 	), bar AS (
 		SELECT
 			t1.rid,
@@ -218,6 +223,7 @@
 		FROM raster_nmapalgebra_in t1
 		JOIN foo t2
 			ON t1.rid = t2.rid
+		OFFSET 0
 	)
 	SELECT
 		rid,
@@ -238,6 +244,7 @@
 			AND t2.rid BETWEEN 10 AND 18
 		WHERE t1.rid = 14
 		GROUP BY t1.rid
+		OFFSET 0
 	), bar AS (
 		SELECT
 			t1.rid,
@@ -251,6 +258,7 @@
 		FROM raster_nmapalgebra_in t1
 		JOIN foo t2
 			ON t1.rid = t2.rid
+		OFFSET 0
 	)
 	SELECT
 		rid,
@@ -271,6 +279,7 @@
 			AND t2.rid BETWEEN 10 AND 18
 		WHERE t1.rid = 17
 		GROUP BY t1.rid
+		OFFSET 0
 	), bar AS (
 		SELECT
 			t1.rid,
@@ -285,6 +294,7 @@
 		FROM raster_nmapalgebra_in t1
 		JOIN foo t2
 			ON t1.rid = t2.rid
+		OFFSET 0
 	)
 	SELECT
 		rid,
@@ -317,6 +327,7 @@
 	CROSS JOIN raster_nmapalgebra_in t2
 	WHERE t1.rid = 20
 		AND t2.rid = 21
+	OFFSET 0
 )
 SELECT
 	rid1,
@@ -337,6 +348,7 @@
 	CROSS JOIN raster_nmapalgebra_in t2
 	WHERE t1.rid = 20
 		AND t2.rid = 22
+	OFFSET 0
 )
 SELECT
 	rid1,
@@ -357,6 +369,7 @@
 	CROSS JOIN raster_nmapalgebra_in t2
 	WHERE t1.rid = 21
 		AND t2.rid = 22
+	OFFSET 0
 )
 SELECT
 	rid1,
@@ -380,6 +393,7 @@
 	CROSS JOIN raster_nmapalgebra_in t2
 	WHERE t1.rid = 20
 		AND t2.rid = 21
+	OFFSET 0
 )
 SELECT
 	rid1,
@@ -403,6 +417,7 @@
 	CROSS JOIN raster_nmapalgebra_in t2
 	WHERE t1.rid = 20
 		AND t2.rid = 22
+	OFFSET 0
 )
 SELECT
 	rid1,
@@ -429,6 +444,7 @@
 	WHERE t1.rid = 20
 		AND t2.rid = 21
 		AND t3.rid = 22
+	OFFSET 0
 )
 SELECT
 	rid1,
@@ -456,6 +472,7 @@
 	WHERE t1.rid = 20
 		AND t2.rid = 21
 		AND t3.rid = 22
+	OFFSET 0
 )
 SELECT
 	rid1,
@@ -483,6 +500,7 @@
 	WHERE t1.rid = 20
 		AND t2.rid = 21
 		AND t3.rid = 22
+	OFFSET 0
 )
 SELECT
 	rid1,
@@ -510,6 +528,7 @@
 	WHERE t1.rid = 20
 		AND t2.rid = 21
 		AND t3.rid = 22
+	OFFSET 0
 )
 SELECT
 	rid1,
@@ -534,6 +553,7 @@
 	WHERE t1.rid = 20
 		AND t2.rid = 21
 		AND t3.rid = 22
+	OFFSET 0
 )
 SELECT
 	rid1,
@@ -557,6 +577,7 @@
 		) AS rast
 	FROM raster_nmapalgebra_in t1
 	WHERE t1.rid = 30
+	OFFSET 0
 )
 SELECT
 	rid,
@@ -573,6 +594,7 @@
 		) AS rast
 	FROM raster_nmapalgebra_in t1
 	WHERE t1.rid = 30
+	OFFSET 0
 )
 SELECT
 	rid,
@@ -590,6 +612,7 @@
 		) AS rast
 	FROM raster_nmapalgebra_in t1
 	WHERE t1.rid = 31
+	OFFSET 0
 )
 SELECT
 	rid,
@@ -610,6 +633,7 @@
 	CROSS JOIN raster_nmapalgebra_in t2
 	WHERE t1.rid = 30
 		AND t2.rid = 31
+	OFFSET 0
 )
 SELECT
 	rid1,
@@ -627,6 +651,7 @@
 		) AS rast
 	FROM raster_nmapalgebra_in t1
 	WHERE t1.rid = 30
+	OFFSET 0
 )
 SELECT
 	rid,
@@ -643,6 +668,7 @@
 		) AS rast
 	FROM raster_nmapalgebra_in t1
 	WHERE t1.rid = 30
+	OFFSET 0
 )
 SELECT
 	rid,



More information about the postgis-tickets mailing list