[postgis-tickets] r15915 - Undefined behaviour in TYPMOD_GET_SRID

Paul Ramsey pramsey at cleverelephant.ca
Fri Oct 6 06:17:34 PDT 2017


Author: pramsey
Date: 2017-10-06 06:17:34 -0700 (Fri, 06 Oct 2017)
New Revision: 15915

Modified:
   branches/2.4/NEWS
   branches/2.4/liblwgeom/cunit/cu_libgeom.c
   branches/2.4/liblwgeom/liblwgeom.h.in
Log:
Undefined behaviour in TYPMOD_GET_SRID
References #3880



Modified: branches/2.4/NEWS
===================================================================
--- branches/2.4/NEWS	2017-10-06 13:12:00 UTC (rev 15914)
+++ branches/2.4/NEWS	2017-10-06 13:17:34 UTC (rev 15915)
@@ -8,7 +8,9 @@
   - #3871, Performance tweak for geometry cmp function
   - #3879, Division by zero in some arc cases
   - #3878, Single defn of signum in header
+  - #3880, Undefined behaviour in TYPMOD_GET_SRID
 
+
 PostGIS 2.4.0
 2017/09/30
 

Modified: branches/2.4/liblwgeom/cunit/cu_libgeom.c
===================================================================
--- branches/2.4/liblwgeom/cunit/cu_libgeom.c	2017-10-06 13:12:00 UTC (rev 15914)
+++ branches/2.4/liblwgeom/cunit/cu_libgeom.c	2017-10-06 13:17:34 UTC (rev 15915)
@@ -35,6 +35,16 @@
 	rv = TYPMOD_GET_SRID(typmod);
 	CU_ASSERT_EQUAL(rv, srid);
 
+        srid = 999999;
+        TYPMOD_SET_SRID(typmod,srid);
+        rv = TYPMOD_GET_SRID(typmod);
+        CU_ASSERT_EQUAL(rv, srid);
+
+        srid = -999999;
+        TYPMOD_SET_SRID(typmod,srid);
+        rv = TYPMOD_GET_SRID(typmod);
+        CU_ASSERT_EQUAL(rv, srid);
+
 	srid = SRID_UNKNOWN;
 	TYPMOD_SET_SRID(typmod,srid);
 	rv = TYPMOD_GET_SRID(typmod);

Modified: branches/2.4/liblwgeom/liblwgeom.h.in
===================================================================
--- branches/2.4/liblwgeom/liblwgeom.h.in	2017-10-06 13:12:00 UTC (rev 15914)
+++ branches/2.4/liblwgeom/liblwgeom.h.in	2017-10-06 13:17:34 UTC (rev 15915)
@@ -161,7 +161,7 @@
 * ZM Flags = Bottom 2 bits.
 */
 
-#define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x1FFFFF00)<<3)>>11)
+#define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x0FFFFF00) - ((typmod) & 0x10000000)) >> 8)
 #define TYPMOD_SET_SRID(typmod, srid) ((typmod) = (((typmod) & 0xE00000FF) | ((srid & 0x001FFFFF)<<8)))
 #define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
 #define TYPMOD_SET_TYPE(typmod, type) ((typmod) = (typmod & 0xFFFFFF03) | ((type & 0x0000003F)<<2))



More information about the postgis-tickets mailing list