|
7 | 7 | * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group |
8 | 8 | * Portions Copyright (c) 1994, Regents of the University of California |
9 | 9 | * |
10 | | - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.236 2006/04/17 18:55:05 tgl Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.237 2006/04/20 04:07:38 tgl Exp $ |
11 | 11 | * |
12 | 12 | *------------------------------------------------------------------------- |
13 | 13 | */ |
@@ -2727,7 +2727,25 @@ ReadRecord(XLogRecPtr *RecPtr, int emode) |
2727 | 2727 | readFile = XLogFileRead(readId, readSeg, emode); |
2728 | 2728 | if (readFile < 0) |
2729 | 2729 | goto next_record_is_invalid; |
2730 | | - readOff = (uint32) (-1); /* force read to occur below */ |
| 2730 | + |
| 2731 | + /* |
| 2732 | + * Whenever switching to a new WAL segment, we read the first page of |
| 2733 | + * the file and validate its header, even if that's not where the |
| 2734 | + * target record is. This is so that we can check the additional |
| 2735 | + * identification info that is present in the first page's "long" |
| 2736 | + * header. |
| 2737 | + */ |
| 2738 | + readOff = 0; |
| 2739 | + if (read(readFile, readBuf, XLOG_BLCKSZ) != XLOG_BLCKSZ) |
| 2740 | + { |
| 2741 | + ereport(emode, |
| 2742 | + (errcode_for_file_access(), |
| 2743 | + errmsg("could not read from log file %u, segment %u, offset %u: %m", |
| 2744 | + readId, readSeg, readOff))); |
| 2745 | + goto next_record_is_invalid; |
| 2746 | + } |
| 2747 | + if (!ValidXLOGHeader((XLogPageHeader) readBuf, emode)) |
| 2748 | + goto next_record_is_invalid; |
2731 | 2749 | } |
2732 | 2750 |
|
2733 | 2751 | targetPageOff = ((RecPtr->xrecoff % XLogSegSize) / XLOG_BLCKSZ) * XLOG_BLCKSZ; |
@@ -3036,6 +3054,15 @@ ValidXLOGHeader(XLogPageHeader hdr, int emode) |
3036 | 3054 | return false; |
3037 | 3055 | } |
3038 | 3056 | } |
| 3057 | + else if (readOff == 0) |
| 3058 | + { |
| 3059 | + /* hmm, first page of file doesn't have a long header? */ |
| 3060 | + ereport(emode, |
| 3061 | + (errmsg("invalid info bits %04X in log file %u, segment %u, offset %u", |
| 3062 | + hdr->xlp_info, readId, readSeg, readOff))); |
| 3063 | + return false; |
| 3064 | + } |
| 3065 | + |
3039 | 3066 | recaddr.xlogid = readId; |
3040 | 3067 | recaddr.xrecoff = readSeg * XLogSegSize + readOff; |
3041 | 3068 | if (!XLByteEQ(hdr->xlp_pageaddr, recaddr)) |
|
0 commit comments