commit 4b4e926fe8c805a7b3abcc8def4009177aa3210a Author: Shoaib Lari Date: Tue Jul 5 10:47:42 2016 -0700 Fix error message for record length too long. Make the error message more descriptive when cannot enlarge buffer inside allocate_recordbuf(). diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c index dcf747c..ae8a82e 100644 --- a/src/backend/access/transam/xlogreader.c +++ b/src/backend/access/transam/xlogreader.c @@ -25,7 +25,8 @@ #include "common/pg_lzcompress.h" #include "replication/origin.h" -static bool allocate_recordbuf(XLogReaderState *state, uint32 reclength); +static bool allocate_recordbuf(XLogReaderState *state, uint32 reclength, + uint32 *newSizeOut); static bool ValidXLogPageHeader(XLogReaderState *state, XLogRecPtr recptr, XLogPageHeader hdr); @@ -110,7 +111,7 @@ XLogReaderAllocate(XLogPageReadCB pagereadfunc, void *private_data) * Allocate an initial readRecordBuf of minimal size, which can later be * enlarged if necessary. */ - if (!allocate_recordbuf(state, 0)) + if (!allocate_recordbuf(state, 0, NULL)) { pfree(state->errormsg_buf); pfree(state->readBuf); @@ -143,7 +144,8 @@ XLogReaderFree(XLogReaderState *state) /* * Allocate readRecordBuf to fit a record of at least the given length. - * Returns true if successful, false if out of memory. + * Returns true if successful, false if out of memory. If newSizeOut is + * non-NULL, it will be set to the size of the attempted allocation. * * readRecordBufSize is set to the new buffer size. * @@ -153,13 +155,16 @@ XLogReaderFree(XLogReaderState *state) * abort records might need more space.) */ static bool -allocate_recordbuf(XLogReaderState *state, uint32 reclength) +allocate_recordbuf(XLogReaderState *state, uint32 reclength, uint32 *newSizeOut) { uint32 newSize = reclength; newSize += XLOG_BLCKSZ - (newSize % XLOG_BLCKSZ); newSize = Max(newSize, 5 * Max(BLCKSZ, XLOG_BLCKSZ)); + if (newSizeOut) + *newSizeOut = newSize; + if (state->readRecordBuf) pfree(state->readRecordBuf); state->readRecordBuf = @@ -201,6 +206,7 @@ XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg) uint32 pageHeaderSize; bool gotheader; int readOff; + uint32 newSizeOut; /* * randAccess indicates whether to verify the previous-record pointer of @@ -334,12 +340,12 @@ XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg) * Enlarge readRecordBuf as needed. */ if (total_len > state->readRecordBufSize && - !allocate_recordbuf(state, total_len)) + !allocate_recordbuf(state, total_len, &newSizeOut)) { - /* We treat this as a "bogus data" condition */ - report_invalid_record(state, "record length %u at %X/%X too long", - total_len, - (uint32) (RecPtr >> 32), (uint32) RecPtr); + report_invalid_record(state, + "cannot allocate %u bytes for record length %u at %X/%X", + newSizeOut, total_len, (uint32) (RecPtr >> 32), + (uint32) RecPtr); goto err; }