Make path_recv() and poly_recv() reject paths/polygons containing no points.
authorTom Lane <[email protected]>
Tue, 18 Dec 2007 00:04:22 +0000 (00:04 +0000)
committerTom Lane <[email protected]>
Tue, 18 Dec 2007 00:04:22 +0000 (00:04 +0000)
The zero-point case is sensible so far as the data structure is concerned,
so maybe we ought to allow it sometime; but right now the textual input
routines for these types don't allow it, and it seems that not all the
functions for the types are prepared to cope.
Report and patch by Merlin Moncure.

src/backend/utils/adt/geo_ops.c

index f55dfc01d6771ddb46c052e4b25c68f3ee616b94..c2626404dcf946302a702bec1d126c87ccd7d238 100644 (file)
@@ -1456,7 +1456,7 @@ path_recv(PG_FUNCTION_ARGS)
 
        closed = pq_getmsgbyte(buf);
        npts = pq_getmsgint(buf, sizeof(int32));
-       if (npts < 0 || npts >= (int32) ((INT_MAX - offsetof(PATH, p[0])) / sizeof(Point)))
+       if (npts <= 0 || npts >= (int32) ((INT_MAX - offsetof(PATH, p[0])) / sizeof(Point)))
                ereport(ERROR,
                                (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
                         errmsg("invalid number of points in external \"path\" value")));
@@ -3484,7 +3484,7 @@ poly_recv(PG_FUNCTION_ARGS)
        int                     size;
 
        npts = pq_getmsgint(buf, sizeof(int32));
-       if (npts < 0 || npts >= (int32) ((INT_MAX - offsetof(POLYGON, p[0])) / sizeof(Point)))
+       if (npts <= 0 || npts >= (int32) ((INT_MAX - offsetof(POLYGON, p[0])) / sizeof(Point)))
                ereport(ERROR,
                                (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
                  errmsg("invalid number of points in external \"polygon\" value")));