From: Regina Obe Date: Mon, 17 Jul 2017 04:45:13 +0000 (+0000) Subject: Credit to OSS-Fuzz X-Git-Tag: 2.4.0alpha~37 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a018a9ae11bfdd850ed948f1978ab42de8b24fd1;p=postgis Credit to OSS-Fuzz 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 --- diff --git a/liblwgeom/ptarray.c b/liblwgeom/ptarray.c index 3bf4fcfd8..d2b0403f3 100644 --- a/liblwgeom/ptarray.c +++ b/liblwgeom/ptarray.c @@ -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