[postgis-tickets] [SCM] PostGIS branch stable-3.1 updated. 3.1.3-25-gef2995b

git at osgeo.org git at osgeo.org
Fri Aug 20 15:10:34 PDT 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, stable-3.1 has been updated
       via  ef2995b4acebeb46581ccbf807b03051aab6a06f (commit)
      from  54534d4b08b537286f9070fc9a0bdd41aa974568 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ef2995b4acebeb46581ccbf807b03051aab6a06f
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Fri Aug 20 15:10:27 2021 -0700

    Fix crashes in aggregate functions, references #4916, #4770, #4724, #4916

diff --git a/NEWS b/NEWS
index ce6bd1f..2d5e47e 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,7 @@ PostGIS 3.1.4dev
   - #4910, Allow repeated points in GML input poslists (Paul Ramsey)
   - #4958, TIGER2020 fix faces and add Tabblock20 (Regina Obe)
   - #4959, Drop Colorado state files also drops national county tables (Regina Obe)
+  - #4916, #4770, #4724, #4916, Crashes in aggregate functions (Paul Ramsey)
 
 
 PostGIS 3.1.3
diff --git a/postgis/lwgeom_out_geobuf.c b/postgis/lwgeom_out_geobuf.c
index 3948f4a..609430b 100644
--- a/postgis/lwgeom_out_geobuf.c
+++ b/postgis/lwgeom_out_geobuf.c
@@ -49,7 +49,7 @@ Datum pgis_asgeobuf_transfn(PG_FUNCTION_ARGS)
 	elog(ERROR, "ST_AsGeobuf: Compiled without protobuf-c support");
 	PG_RETURN_NULL();
 #else
-	MemoryContext aggcontext;
+	MemoryContext aggcontext, oldcontext;
 	struct geobuf_agg_context *ctx;
 
 	/* We need to initialize the internal cache to access it later via postgis_oid() */
@@ -57,7 +57,7 @@ Datum pgis_asgeobuf_transfn(PG_FUNCTION_ARGS)
 
 	if (!AggCheckCallContext(fcinfo, &aggcontext))
 		elog(ERROR, "pgis_asgeobuf_transfn: called in non-aggregate context");
-	MemoryContextSwitchTo(aggcontext);
+	oldcontext = MemoryContextSwitchTo(aggcontext);
 
 	if (PG_ARGISNULL(0)) {
 		ctx = palloc(sizeof(*ctx));
@@ -72,9 +72,16 @@ Datum pgis_asgeobuf_transfn(PG_FUNCTION_ARGS)
 
 	if (!type_is_rowtype(get_fn_expr_argtype(fcinfo->flinfo, 1)))
 		elog(ERROR, "pgis_asgeobuf_transfn: parameter row cannot be other than a rowtype");
+
+	/* Null input tuple => null result */
+	if (PG_ARGISNULL(1)) {
+		PG_RETURN_NULL();
+	}
+
 	ctx->row = PG_GETARG_HEAPTUPLEHEADER(1);
 
 	geobuf_agg_transfn(ctx);
+	MemoryContextSwitchTo(oldcontext);
 	PG_RETURN_POINTER(ctx);
 #endif
 }
diff --git a/raster/rt_pg/rtpg_mapalgebra.c b/raster/rt_pg/rtpg_mapalgebra.c
index be183b8..8a4f162 100644
--- a/raster/rt_pg/rtpg_mapalgebra.c
+++ b/raster/rt_pg/rtpg_mapalgebra.c
@@ -2163,7 +2163,7 @@ Datum RASTER_union_transfn(PG_FUNCTION_ARGS)
 	if (PG_ARGISNULL(0)) {
 		POSTGIS_RT_DEBUG(3, "Creating state variable");
 		/* allocate container in aggcontext */
-		iwr = palloc(sizeof(struct rtpg_union_arg_t));
+		iwr = MemoryContextAlloc(aggcontext, sizeof(struct rtpg_union_arg_t));
 		if (iwr == NULL) {
 			MemoryContextSwitchTo(oldcontext);
 			elog(ERROR, "RASTER_union_transfn: Could not allocate memory for state variable");
@@ -2932,8 +2932,12 @@ Datum RASTER_union_finalfn(PG_FUNCTION_ARGS)
 	}
 
 	/* cleanup */
-	pfree(itrset);
-	rtpg_union_arg_destroy(iwr);
+	/* For Windowing functions, it is important to leave */
+	/* the state intact, knowing that the aggcontext will be */
+	/* freed by PgSQL when the statement is complete. */
+	/* https://trac.osgeo.org/postgis/ticket/4770 */
+	// pfree(itrset);
+	// rtpg_union_arg_destroy(iwr);
 
 	if (!_rtn) PG_RETURN_NULL();
 
diff --git a/raster/rt_pg/rtpg_statistics.c b/raster/rt_pg/rtpg_statistics.c
index 649d7f7..4db8f72 100644
--- a/raster/rt_pg/rtpg_statistics.c
+++ b/raster/rt_pg/rtpg_statistics.c
@@ -900,7 +900,11 @@ Datum RASTER_summaryStats_finalfn(PG_FUNCTION_ARGS)
 	result = HeapTupleGetDatum(tuple);
 
 	/* clean up */
-	rtpg_summarystats_arg_destroy(state);
+	/* For Windowing functions, it is important to leave */
+	/* the state intact, knowing that the aggcontext will be */
+	/* freed by PgSQL when the statement is complete. */
+	/* https://trac.osgeo.org/postgis/ticket/4770 */
+	// rtpg_summarystats_arg_destroy(state);
 
 	PG_RETURN_DATUM(result);
 }
diff --git a/raster/test/regress/tickets.sql b/raster/test/regress/tickets.sql
index 711a7ad..a227171 100644
--- a/raster/test/regress/tickets.sql
+++ b/raster/test/regress/tickets.sql
@@ -144,4 +144,19 @@ SELECT '#4547.2', AddRasterConstraints('ticket_4547', 'r');
 DROP TABLE ticket_4547;
 
 -- #4769
-SELECT '#4769', st_addband(NULL, NULL::_raster, 1, 1);
\ No newline at end of file
+SELECT '#4769', st_addband(NULL, NULL::_raster, 1, 1);
+
+SELECT '#4770.a',
+ ST_Union(NULL::raster) OVER (ORDER BY b)
+FROM (VALUES ('A0006', 300), ('A0006', 302)) t(a,b);
+
+SELECT '#4770.b',
+ ST_Union(NULL::raster) OVER (PARTITION BY a ORDER BY b)
+FROM (VALUES ('A0006', 300),
+	         ('A0006', 302)) t(a, b);
+
+SELECT '#4724.a', ST_SummaryStatsAgg(NULL::raster, NULL::int4, NULL::bool)
+ OVER (ORDER BY q) FROM generate_series(1,2) AS e(q);
+
+SELECT '#4724.b', ST_SummaryStatsAgg(NULL::raster, NULL::int4, NULL::bool)
+ FROM generate_series(1,2) AS e(q);
diff --git a/raster/test/regress/tickets_expected b/raster/test/regress/tickets_expected
index ae1f56b..46e1297 100644
--- a/raster/test/regress/tickets_expected
+++ b/raster/test/regress/tickets_expected
@@ -70,3 +70,10 @@ NOTICE:  Adding out-of-database constraint
 NOTICE:  Adding maximum extent constraint
 #4547.2|t
 #4769|
+#4770.a|
+#4770.a|
+#4770.b|
+#4770.b|
+#4724.a|(0,,,,,)
+#4724.a|(0,,,,,)
+#4724.b|(0,,,,,)
diff --git a/regress/core/tickets.sql b/regress/core/tickets.sql
index 51cef68..9f95ac0 100644
--- a/regress/core/tickets.sql
+++ b/regress/core/tickets.sql
@@ -1397,3 +1397,38 @@ SELECT '#4949', 'Arctic Stereographic forward', ST_AsEWKT(ST_SnapToGrid(ST_Trans
 -- Antarctic Polar Stereographic -- SRID=3031;POINT(-2399498.7 3213318.5)
 SELECT '#4949', 'Antarctic Stereographic forward', ST_AsEWKT(ST_SnapToGrid(ST_Transform(
   'SRID=4326;POINT(-36.75 -54.25)'::geometry, 3031),0.1));
+
+
+-- #4916, #4770, #4724, #4916, #4940
+SELECT '#4770.a',
+ ST_Union(NULL::geometry) OVER (ORDER BY b)
+FROM (VALUES ('A0006', 300),
+           ('A0006', 302)) t(a, b);
+
+WITH w AS (
+  SELECT
+    ST_Union(g) OVER (PARTITION BY b ORDER BY a) AS g,
+    Sum(b) OVER (PARTITION BY b ORDER BY a) AS s
+  FROM (VALUES ('POINT(0 0)'::geometry, 'A0006', 300),
+                 ('POINT(1 1)'::geometry, 'A0006', 302)) t(g, a, b)
+)
+SELECT '#4770.b', ST_AsText(g), s FROM w;
+
+WITH w AS (
+  SELECT
+    ST_Union(g) OVER (PARTITION BY a ORDER BY b) AS g,
+    Sum(b) OVER (PARTITION BY a ORDER BY b) AS s
+  FROM (VALUES ('POINT(0 0)'::geometry, 'A0006', 300),
+                 ('POINT(1 1)'::geometry, 'A0006', 302)) t(g, a, b)
+)
+SELECT '#4770.c', ST_AsText(g), s FROM w;
+
+SELECT '#4916.a', ST_AsGeobuf(NULL::pg_class, 'g') over (order by b)
+FROM (VALUES ('POINT(0 0)'::geometry, 'A0006', 300),
+           ('POINT(1 1)'::geometry, 'A0006', 302)) t(g, a, b);
+
+SELECT '#4916.b', ST_AsGeobuf(NULL::pg_class) over (order by b)
+FROM (VALUES ('POINT(0 0)'::geometry, 'A0006', 300),
+           ('POINT(1 1)'::geometry, 'A0006', 302)) t(g, a, b);
+
+------
diff --git a/regress/core/tickets_expected b/regress/core/tickets_expected
index cf019c1..4d39f32 100644
--- a/regress/core/tickets_expected
+++ b/regress/core/tickets_expected
@@ -454,3 +454,13 @@ ERROR:  LWGEOM_addpoint: Invalid offset
 #4949|North Pole LAEA inverse|SRID=4326;POINT(19.4921659 69.7902258)
 #4949|Arctic Stereographic forward|SRID=3413;POINT(2218082.1 -1409150)
 #4949|Antarctic Stereographic forward|SRID=3031;POINT(-2399498.7 3213318.5)
+#4770.a|
+#4770.a|
+#4770.b|POINT(0 0)|300
+#4770.b|POINT(1 1)|302
+#4770.c|POINT(0 0)|300
+#4770.c|MULTIPOINT(0 0,1 1)|602
+#4916.a|
+#4916.a|
+#4916.b|
+#4916.b|

-----------------------------------------------------------------------

Summary of changes:
 NEWS                                 |  1 +
 postgis/lwgeom_out_geobuf.c          | 11 +++++++++--
 raster/rt_pg/rtpg_mapalgebra.c       | 10 +++++++---
 raster/rt_pg/rtpg_statistics.c       |  6 +++++-
 raster/test/regress/tickets.sql      | 17 ++++++++++++++++-
 raster/test/regress/tickets_expected |  7 +++++++
 regress/core/tickets.sql             | 35 +++++++++++++++++++++++++++++++++++
 regress/core/tickets_expected        | 10 ++++++++++
 8 files changed, 90 insertions(+), 7 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list