Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteac825a

Browse files
committed
Ensure that we validate the page header of the first page of a WAL file
whenever we start to read within that file. The first page carriesextra identification information that really ought to be checked, butas the code stood, this was only checked when we switched sequentiallyinto a new WAL file, or if by chance the starting checkpoint record waswithin the first page. This patch ensures that we will detect bogus'long header' information before we start replaying the WAL sequence.
1 parentcc7eab3 commiteac825a

File tree

1 file changed

+29
-2
lines changed
  • src/backend/access/transam

1 file changed

+29
-2
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
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 $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -2727,7 +2727,25 @@ ReadRecord(XLogRecPtr *RecPtr, int emode)
27272727
readFile=XLogFileRead(readId,readSeg,emode);
27282728
if (readFile<0)
27292729
gotonext_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+
gotonext_record_is_invalid;
2746+
}
2747+
if (!ValidXLOGHeader((XLogPageHeader)readBuf,emode))
2748+
gotonext_record_is_invalid;
27312749
}
27322750

27332751
targetPageOff= ((RecPtr->xrecoff %XLogSegSize) /XLOG_BLCKSZ)*XLOG_BLCKSZ;
@@ -3036,6 +3054,15 @@ ValidXLOGHeader(XLogPageHeader hdr, int emode)
30363054
return false;
30373055
}
30383056
}
3057+
elseif (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+
30393066
recaddr.xlogid=readId;
30403067
recaddr.xrecoff=readSeg*XLogSegSize+readOff;
30413068
if (!XLByteEQ(hdr->xlp_pageaddr,recaddr))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp