[postgis-tickets] [SCM] PostGIS branch stable-3.0 updated. 3.0.3-38-g22dec99

git at osgeo.org git at osgeo.org
Fri Aug 20 15:23:15 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.0 has been updated
       via  22dec99042910bda7d950ada5c490b80ea353bd6 (commit)
      from  f6e37c3e70dca282d99829bba13137cb913f191a (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 22dec99042910bda7d950ada5c490b80ea353bd6
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Fri Aug 20 15:23:07 2021 -0700

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

diff --git a/NEWS b/NEWS
index cd97aec..a00da7d 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,7 @@ PostGIS 3.0.4dev
   - #4740, Round values in geography_distance_tree
            as we do on geography_distance (Raúl Marín, Paul Ramsey, Regina Obe)
   - #4968, Update autogen.sh to handle autoconf 2.71 issues (Raúl Marín, Regina Obe)
+  - #4916, #4770, #4724, #4916, Crashes in aggregate functions (Paul Ramsey)
 
 
 PostGIS 3.0.3
diff --git a/postgis/lwgeom_out_geobuf.c b/postgis/lwgeom_out_geobuf.c
index f375397..e09cbc6 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: Missing libprotobuf-c >= version 1.1");
 	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 0caede2..7408506 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 bb1e51c..07c95f1 100644
--- a/raster/rt_pg/rtpg_statistics.c
+++ b/raster/rt_pg/rtpg_statistics.c
@@ -902,7 +902,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 30ffa63..cbbf801 100644
--- a/regress/core/tickets.sql
+++ b/regress/core/tickets.sql
@@ -1358,3 +1358,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 ad893bb..f20716e 100644
--- a/regress/core/tickets_expected
+++ b/regress/core/tickets_expected
@@ -448,3 +448,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