]> granicus.if.org Git - postgis/commitdiff
Credit to OSS-Fuzz
authorRegina Obe <lr@pcorp.us>
Mon, 17 Jul 2017 04:45:13 +0000 (04:45 +0000)
committerRegina Obe <lr@pcorp.us>
Mon, 17 Jul 2017 04:45:13 +0000 (04:45 +0000)
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2590

References #3786 for PostGIS 2.4/trunk

git-svn-id: http://svn.osgeo.org/postgis/trunk@15487 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/ptarray.c

index 3bf4fcfd82b54a9b60c4d7692069e0d9b8832f9e..d2b0403f3312b086765da43017a87a47132ac9bb 100644 (file)
@@ -679,6 +679,13 @@ ptarray_clone(const POINTARRAY *in)
 int
 ptarray_is_closed(const POINTARRAY *in)
 {
+       if (!in)
+       {
+               lwerror("ptarray_is_closed: called with null point array");
+               return 0;
+       }
+       if (in->npoints <= 1 ) return in->npoints; /* single-point are closed, empty not closed */
+
        return 0 == memcmp(getPoint_internal(in, 0), getPoint_internal(in, in->npoints-1), ptarray_point_size(in));
 }
 
@@ -686,13 +693,27 @@ ptarray_is_closed(const POINTARRAY *in)
 int
 ptarray_is_closed_2d(const POINTARRAY *in)
 {
-       return 0 == memcmp(getPoint_internal(in, 0), getPoint_internal(in, in->npoints-1), sizeof(POINT2D));
+       if (!in)
+       {
+               lwerror("ptarray_is_closed_2d: called with null point array");
+               return 0;
+       }
+       if (in->npoints <= 1 ) return in->npoints; /* single-point are closed, empty not closed */
+
+       return 0 == memcmp(getPoint_internal(in, 0), getPoint_internal(in, in->npoints-1), sizeof(POINT2D) );
 }
 
 int
 ptarray_is_closed_3d(const POINTARRAY *in)
 {
-       return 0 == memcmp(getPoint_internal(in, 0), getPoint_internal(in, in->npoints-1), sizeof(POINT3D));
+       if (!in)
+       {
+               lwerror("ptarray_is_closed_3d: called with null point array");
+               return 0;
+       }
+       if (in->npoints <= 1 ) return in->npoints; /* single-point are closed, empty not closed */
+
+       return 0 == memcmp(getPoint_internal(in, 0), getPoint_internal(in, in->npoints-1), sizeof(POINT3D) );
 }
 
 int