File tree Expand file tree Collapse file tree 3 files changed +30
-6
lines changed
spatial/include/spatial/core/geometry Expand file tree Collapse file tree 3 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -220,8 +220,13 @@ class GeometryProcessor {
220220public:
221221 RESULT Process (const geometry_t &geom, ARGS... args) {
222222
223- has_z = geom.GetProperties ().HasZ ();
224- has_m = geom.GetProperties ().HasM ();
223+ const auto props = geom.GetProperties ();
224+
225+ // Check the version
226+ props.CheckVersion ();
227+
228+ has_z = props.HasZ ();
229+ has_m = props.HasM ();
225230 nesting_level = 0 ;
226231 current_type = geom.GetType ();
227232 parent_type = GeometryType::POINT;
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ namespace spatial {
55
66namespace core {
77
8+ static constexpr const uint8_t GEOMETRY_VERSION = 0 ;
9+
810struct GeometryProperties {
911private:
1012 static constexpr const uint8_t Z = 0x01 ;
@@ -14,6 +16,8 @@ struct GeometryProperties {
1416 // static constexpr const uint8_t EMPTY = 0x08;
1517 // static constexpr const uint8_t GEODETIC = 0x10;
1618 // static constexpr const uint8_t SOLID = 0x20;
19+ static constexpr const uint8_t VERSION_1 = 0x40 ;
20+ static constexpr const uint8_t VERSION_0 = 0x80 ;
1721 uint8_t flags = 0 ;
1822
1923public:
@@ -24,6 +28,16 @@ struct GeometryProperties {
2428 SetM (has_m);
2529 }
2630
31+ inline void CheckVersion () const {
32+ const auto v0 = (flags & VERSION_0);
33+ const auto v1 = (flags & VERSION_1);
34+ if ((v1 | v0) != GEOMETRY_VERSION) {
35+ throw NotImplementedException (
36+ " This geometry seems to be written with a newer version of the DuckDB spatial library that is not "
37+ " compatible with this version. Please upgrade your DuckDB installation." );
38+ }
39+ }
40+
2741 inline bool HasZ () const {
2842 return (flags & Z) != 0 ;
2943 }
Original file line number Diff line number Diff line change @@ -83,13 +83,15 @@ class geometry_t {
8383 }
8484
8585 GeometryType GetType () const {
86+ // return the type
8687 return Load<GeometryType>(const_data_ptr_cast (data.GetPrefix ()));
8788 }
89+
8890 GeometryProperties GetProperties () const {
89- return Load<GeometryProperties>(const_data_ptr_cast (data.GetPrefix () + 1 ));
90- }
91- uint16_t GetHash () const {
92- return Load< uint16_t >( const_data_ptr_cast (data. GetPrefix () + 2 )) ;
91+ const auto props = Load<GeometryProperties>(const_data_ptr_cast (data.GetPrefix () + 1 ));
92+ // Check the version
93+ props. CheckVersion ();
94+ return props ;
9395 }
9496
9597 bool TryGetCachedBounds (Box2D<double > &bbox) const {
@@ -101,6 +103,9 @@ class geometry_t {
101103 auto hash = cursor.Read <uint16_t >();
102104 (void )hash;
103105
106+ // Check the version
107+ properties.CheckVersion ();
108+
104109 if (properties.HasBBox ()) {
105110 cursor.Skip (4 ); // skip padding
106111
You can’t perform that action at this time.
0 commit comments