Skip to content

Commit c6a9191

Browse files
hlinnakaCommitfest Bot
authored andcommitted
Add runtime checks for bogus multixact offsets
These are not directly related to 64 bit offsets, but makes sense I think
1 parent b27b65f commit c6a9191

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/backend/access/transam/multixact.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,7 @@ GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members,
11541154
int slotno;
11551155
MultiXactOffset *offptr;
11561156
MultiXactOffset offset;
1157+
MultiXactOffset nextMXOffset;
11571158
int length;
11581159
MultiXactId oldestMXact;
11591160
MultiXactId nextMXact;
@@ -1245,12 +1246,14 @@ GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members,
12451246
offptr += entryno;
12461247
offset = *offptr;
12471248

1248-
Assert(offset != 0);
1249+
if (offset == 0)
1250+
ereport(ERROR,
1251+
(errcode(ERRCODE_DATA_CORRUPTED),
1252+
errmsg("MultiXact %u has invalid offset", multi)));
12491253

12501254
/* read next multi's offset */
12511255
{
12521256
MultiXactId tmpMXact;
1253-
MultiXactOffset nextMXOffset;
12541257

12551258
/* handle wraparound if needed */
12561259
tmpMXact = multi + 1;
@@ -1284,21 +1287,27 @@ GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members,
12841287
offptr = (MultiXactOffset *) MultiXactOffsetCtl->shared->page_buffer[slotno];
12851288
offptr += entryno;
12861289
nextMXOffset = *offptr;
1287-
1288-
if (nextMXOffset == 0)
1289-
ereport(ERROR,
1290-
(errcode(ERRCODE_DATA_CORRUPTED),
1291-
errmsg("MultiXact %u has invalid next offset",
1292-
multi)));
1293-
1294-
length = nextMXOffset - offset;
12951290
}
12961291

12971292
LWLockRelease(lock);
12981293
lock = NULL;
12991294

1300-
/* A multixid with zero members should not happen */
1301-
Assert(length > 0);
1295+
/* Sanity check the next offset */
1296+
if (nextMXOffset == 0)
1297+
ereport(ERROR,
1298+
(errcode(ERRCODE_DATA_CORRUPTED),
1299+
errmsg("MultiXact %u has invalid next offset", multi)));
1300+
if (nextMXOffset < offset)
1301+
ereport(ERROR,
1302+
(errcode(ERRCODE_DATA_CORRUPTED),
1303+
errmsg("MultiXact %u has offset (%" PRIu64") greater than its next offset (%" PRIu64")",
1304+
multi, offset, nextMXOffset)));
1305+
if (nextMXOffset - offset > INT32_MAX)
1306+
ereport(ERROR,
1307+
(errcode(ERRCODE_DATA_CORRUPTED),
1308+
errmsg("MultiXact %u has too many members (%" PRIu64 ")",
1309+
multi, nextMXOffset - offset)));
1310+
length = nextMXOffset - offset;
13021311

13031312
/* read the members */
13041313
ptr = (MultiXactMember *) palloc(length * sizeof(MultiXactMember));

0 commit comments

Comments
 (0)