Subject: [PATCH 9/9] Fix crash in multirange_intersect_multirange_internal

From: Alvaro Herrera <[email-masked]>
Date: Thu, 26 Sep 2019 18:01:04 -0300

---
 src/backend/utils/adt/multirangetypes.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/backend/utils/adt/multirangetypes.c b/src/backend/utils/adt/multirangetypes.c
index c85f5dc90d..7717acb3b1 100644
--- a/src/backend/utils/adt/multirangetypes.c
+++ b/src/backend/utils/adt/multirangetypes.c
@@ -1123,7 +1123,8 @@ multirange_intersect_multirange(PG_FUNCTION_ARGS)
 
 MultirangeType *
 multirange_intersect_multirange_internal(Oid mltrngtypoid, TypeCacheEntry *rangetyp,
-										 int32 range_count1, RangeType **ranges1, int32 range_count2, RangeType **ranges2)
+										 int32 range_count1, RangeType **ranges1,
+										 int32 range_count2, RangeType **ranges2)
 {
 	RangeType  *r1;
 	RangeType  *r2;
@@ -1132,6 +1133,9 @@ multirange_intersect_multirange_internal(Oid mltrngtypoid, TypeCacheEntry *range
 	int32		i1;
 	int32		i2;
 
+	if (range_count1 == 0 || range_count2 == 0)
+		return make_multirange(mltrngtypoid, rangetyp, 0, NULL);
+
 	/*
 	 * Worst case is a stitching pattern like this:
 	 *
-- 
2.17.1

--G4iJoqBmSsgzjUCe--