[postgis-tickets] [SCM] PostGIS branch master updated. 3.2.0beta2-5-gd71751919

git at osgeo.org git at osgeo.org
Sat Nov 27 13:47:27 PST 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, master has been updated
       via  d71751919c84ae83fa32268197caced462154ab2 (commit)
       via  1d175e47ab884e6b543c014e16297b434f462006 (commit)
      from  eda70258f373c1ad88e1851f194c891ad8d9aff4 (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 d71751919c84ae83fa32268197caced462154ab2
Merge: eda70258f 1d175e47a
Author: bjornharrtell <bjorn at wololo.org>
Date:   Sat Nov 27 13:47:27 2021 -0800

    Merge pull request 'Catch and bail on mixed geometry type' (!64) from bjornharrtell/postgis:issue-5028 into master
    
    Reviewed-on: https://git.osgeo.org/gitea/postgis/postgis/pulls/64


commit 1d175e47ab884e6b543c014e16297b434f462006
Author: Björn Harrtell <bjorn at wololo.org>
Date:   Sat Nov 27 22:43:42 2021 +0100

    Catch and bail on mixed geometry type

diff --git a/deps/flatgeobuf/flatgeobuf_c.cpp b/deps/flatgeobuf/flatgeobuf_c.cpp
index 2ef2dd401..7c61534a2 100644
--- a/deps/flatgeobuf/flatgeobuf_c.cpp
+++ b/deps/flatgeobuf/flatgeobuf_c.cpp
@@ -35,7 +35,6 @@ typedef flatgeobuf_ctx ctx;
 
 uint8_t flatgeobuf_magicbytes[] = { 0x66, 0x67, 0x62, 0x03, 0x66, 0x67, 0x62, 0x01 };
 uint8_t FLATGEOBUF_MAGICBYTES_SIZE = sizeof(flatgeobuf_magicbytes);
-uint8_t FLATGEOBUF_MAGICBYTES_LEN = (sizeof(flatgeobuf_magicbytes) / sizeof((flatgeobuf_magicbytes)[0]));
 
 struct FeatureItem : FlatGeobuf::Item {
     uoffset_t size;
@@ -53,6 +52,7 @@ int flatgeobuf_encode_header(ctx *ctx)
             ctx->srid = ctx->lwgeom->srid;
 		ctx->has_z = lwgeom_has_z(ctx->lwgeom);
 		ctx->has_m = lwgeom_has_m(ctx->lwgeom);
+        ctx->lwgeom_type = ctx->lwgeom->type;
 		ctx->geometry_type = (uint8_t) GeometryWriter::get_geometrytype(ctx->lwgeom);
 	} else {
 		LWDEBUG(2, "ctx->lwgeom is null");
@@ -121,6 +121,10 @@ int flatgeobuf_encode_feature(ctx *ctx)
 
     if (ctx->lwgeom != NULL && !lwgeom_is_empty(ctx->lwgeom)) {
         LWDEBUGG(3, ctx->lwgeom, "GeometryWriter input LWGEOM");
+        if (ctx->lwgeom_type != ctx->lwgeom->type) {
+            lwerror("mixed geometry type is not supported");
+            return -1;
+        }
         GeometryWriter writer(fbb, ctx->lwgeom, (GeometryType) ctx->geometry_type, ctx->has_z, ctx->has_m);
         geometry = writer.write(0);
     }
@@ -192,19 +196,19 @@ void flatgeobuf_create_index(ctx *ctx)
     // allocate new buffer and write magicbytes
     auto oldbuf = ctx->buf;
     auto oldoffset = ctx->offset;
-    ctx->buf = (uint8_t *) lwalloc(sizeof(signed int) + sizeof(flatgeobuf_magicbytes));
-    memcpy(ctx->buf + sizeof(signed int), flatgeobuf_magicbytes, sizeof(flatgeobuf_magicbytes));
-    ctx->offset = sizeof(signed int) + sizeof(flatgeobuf_magicbytes);
+    ctx->buf = (uint8_t *) lwalloc(sizeof(signed int) + FLATGEOBUF_MAGICBYTES_SIZE);
+    memcpy(ctx->buf + sizeof(signed int), flatgeobuf_magicbytes, FLATGEOBUF_MAGICBYTES_SIZE);
+    ctx->offset = sizeof(signed int) + FLATGEOBUF_MAGICBYTES_SIZE;
     // write new header
     flatgeobuf_encode_header(ctx);
     // create and write index
+    PackedRTree tree(items, extent, ctx->index_node_size);
     const auto writeData = [&ctx] (const void *data, const size_t size) {
         ctx->buf = (uint8_t *) lwrealloc(ctx->buf, ctx->offset + size);
         memcpy(ctx->buf + ctx->offset, data, size);
+        ctx->offset += size;
     };
-    PackedRTree tree(items, extent, ctx->index_node_size);
     tree.streamWrite(writeData);
-    ctx->offset += tree.size();
     // read items and write in sorted order
     for (auto item : items) {
         auto featureItem = std::static_pointer_cast<FeatureItem>(item);
@@ -235,13 +239,6 @@ int flatgeobuf_decode_feature(ctx *ctx)
 
     const auto geometry = feature->geometry();
     if (geometry != nullptr) {
-        if (geometry->ends() != nullptr) {
-            LWDEBUGF(3, "ENDS: %d", geometry->ends()->size());
-            for (uint32_t i = 0; i < geometry->ends()->size(); i++) {
-                LWDEBUGF(3, "ENDS: %d", geometry->ends()->Get(i));
-            }
-        }
-
         LWDEBUGF(3, "Constructing GeometryReader with geometry_type %d has_z %d haz_m %d", ctx->geometry_type, ctx->has_z, ctx->has_m);
         GeometryReader reader(geometry, (GeometryType) ctx->geometry_type, ctx->has_z, ctx->has_m);
         ctx->lwgeom = reader.read();
diff --git a/deps/flatgeobuf/flatgeobuf_c.h b/deps/flatgeobuf/flatgeobuf_c.h
index 8ba401ddb..b5ea062bf 100644
--- a/deps/flatgeobuf/flatgeobuf_c.h
+++ b/deps/flatgeobuf/flatgeobuf_c.h
@@ -34,7 +34,6 @@ extern "C" {
 
 extern uint8_t flatgeobuf_magicbytes[];
 extern uint8_t FLATGEOBUF_MAGICBYTES_SIZE;
-extern uint8_t FLATGEOBUF_MAGICBYTES_LEN;
 
 // need c compatible variant of this enum
 #define flatgeobuf_column_type_byte UINT8_C(0)
@@ -104,6 +103,7 @@ typedef struct flatgeobuf_ctx
     uint64_t size;
 
     LWGEOM *lwgeom;
+	uint8_t lwgeom_type;
     uint8_t *properties;
 	uint32_t properties_len;
     uint32_t properties_size;
diff --git a/postgis/flatgeobuf.c b/postgis/flatgeobuf.c
index 566e6cdca..1b502e546 100644
--- a/postgis/flatgeobuf.c
+++ b/postgis/flatgeobuf.c
@@ -268,10 +268,10 @@ void flatgeobuf_check_magicbytes(struct flatgeobuf_decode_ctx *ctx)
 	uint8_t *buf = ctx->ctx->buf + ctx->ctx->offset;
 	uint32_t i;
 
-	for (i = 0; i < FLATGEOBUF_MAGICBYTES_LEN / 2; i++)
+	for (i = 0; i < FLATGEOBUF_MAGICBYTES_SIZE / 2; i++)
 		if (buf[i] != flatgeobuf_magicbytes[i])
 			elog(ERROR, "Data is not FlatGeobuf");
-	ctx->ctx->offset += FLATGEOBUF_MAGICBYTES_LEN;
+	ctx->ctx->offset += FLATGEOBUF_MAGICBYTES_SIZE;
 }
 
 static void decode_properties(struct flatgeobuf_decode_ctx *ctx, Datum *values, bool *isnull)
diff --git a/regress/core/flatgeobuf.sql b/regress/core/flatgeobuf.sql
index 15df3aaab..c2e9167e7 100644
--- a/regress/core/flatgeobuf.sql
+++ b/regress/core/flatgeobuf.sql
@@ -104,6 +104,15 @@ select 'P1', id, ST_AsText(geom) from ST_FromFlatGeobuf(null::flatgeobuf_t1, (
     ) q)
 );
 
+-- Multiple 2D points and a polygon
+select 'PL1', id, ST_AsText(geom) from ST_FromFlatGeobuf(null::flatgeobuf_t1, (
+    select ST_AsFlatGeobuf(q) from (values
+        ('POINT (1 2)'::geometry),
+        ('POINT (3 4)'::geometry),
+        ('POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10), (20 30, 35 35, 30 20, 20 30))'::geometry)
+    ) q)
+);
+
 select '--- Attribute roundtrips ---';
 
 select ST_TableFromFlatGeobuf('public', 'flatgeobuf_a1', (select ST_AsFlatGeobuf(q) fgb from (select
diff --git a/regress/core/flatgeobuf_expected b/regress/core/flatgeobuf_expected
index bb17110b6..60f3ab847 100644
--- a/regress/core/flatgeobuf_expected
+++ b/regress/core/flatgeobuf_expected
@@ -19,6 +19,7 @@ GC1|0|GEOMETRYCOLLECTION(POINT(40 10),LINESTRING(10 10,20 20,10 40),POLYGON((40
 --- Multiple rows ---
 P1|0|POINT(1 2)
 P1|1|POINT(3 4)
+ERROR:  mixed geometry type is not supported
 --- Attribute roundtrips ---
 A1|0||t|1|2|3|4|1.2|1.3|2016-06-23 03:44:52.134125+00|hello
 --- Exotic roundtrips ---

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

Summary of changes:
 deps/flatgeobuf/flatgeobuf_c.cpp | 23 ++++++++++-------------
 deps/flatgeobuf/flatgeobuf_c.h   |  2 +-
 postgis/flatgeobuf.c             |  4 ++--
 regress/core/flatgeobuf.sql      |  9 +++++++++
 regress/core/flatgeobuf_expected |  1 +
 5 files changed, 23 insertions(+), 16 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list