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

Commit9e1b441

Browse files
committed
Allocate static pages in memory strictly MAXALIGNed to avoid overflow
due to adding padding bytes by Postgres data access alignment macros.This was the source of rare but dangerous segfault on 32-bit FreeBSDbut no system was safe as static alignment is completelysystem/compiler free choice.This problem was hidden by the added completely unrelated variabletrace_sort way before the relevant part of the code. It just shiftedthe alignment of all variables with bigger address values toacceptable but haven't solved the problem at large.
1 parent7930600 commit9e1b441

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

‎src/rumdatapage.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,14 @@ dataPlaceToPage(RumBtree btree, Page page, OffsetNumber off)
853853
ItemPointerDataiptr= {{0,0},0};
854854
RumItemcopyItem;
855855
boolcopyItemEmpty= true;
856-
charpageCopy[BLCKSZ];
856+
/*
857+
* Must have pageCopy MAXALIGNed to use PG macros to access data in
858+
* it. Should not rely on compiler alignment preferences to avoid
859+
* pageCopy overflow related to PG in-memory page items alignment
860+
* inside rumDataPageLeafRead() or elsewhere.
861+
*/
862+
charpageCopyStorage[BLCKSZ+MAXIMUM_ALIGNOF];
863+
char*pageCopy= (char*)MAXALIGN(pageCopyStorage);
857864
intmaxoff=RumPageGetOpaque(page)->maxoff;
858865
intfreespace,
859866
insertCount=0;
@@ -1055,7 +1062,14 @@ dataSplitPageLeaf(RumBtree btree, Buffer lbuf, Buffer rbuf,
10551062
RumItemitem;
10561063
inttotalCount=0;
10571064
intmaxItemIndex=btree->curitem;
1058-
staticcharlpageCopy[BLCKSZ];
1065+
/*
1066+
* Must have lpageCopy MAXALIGNed to use PG macros to access data in
1067+
* it. Should not rely on compiler alignment preferences to avoid
1068+
* lpageCopy overflow related to PG in-memory page items alignment
1069+
* inside rumDataPageLeafRead() etc.
1070+
*/
1071+
staticcharlpageCopyStorage[BLCKSZ+MAXIMUM_ALIGNOF];
1072+
char*lpageCopy= (char*)MAXALIGN(lpageCopyStorage);
10591073

10601074
memset(&item,0,sizeof(item));
10611075
dataPrepareData(btree,newlPage,off);
@@ -1233,8 +1247,14 @@ dataSplitPageInternal(RumBtree btree, Buffer lbuf, Buffer rbuf,
12331247
OffsetNumbermaxoff=RumPageGetOpaque(newlPage)->maxoff;
12341248
SizepageSize=PageGetPageSize(newlPage);
12351249
SizefreeSpace;
1236-
1237-
staticcharvector[2*BLCKSZ];
1250+
/*
1251+
* Must have vector MAXALIGNed to use PG macros to access data in
1252+
* it. Should not rely on compiler alignment preferences to avoid
1253+
* vector overflow related to PG in-memory page items alignment
1254+
* inside rumDataPageLeafRead() etc.
1255+
*/
1256+
staticcharvectorStorage[2*BLCKSZ+MAXIMUM_ALIGNOF];
1257+
char*vector= (char*)MAXALIGN(vectorStorage);
12381258

12391259
RumInitPage(rPage,RumPageGetOpaque(newlPage)->flags,pageSize);
12401260
freeSpace=RumDataPageGetFreeSpace(rPage);

‎src/rumentrypage.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,14 @@ entrySplitPage(RumBtree btree, Buffer lbuf, Buffer rbuf,
428428
Pagepage;
429429
PagenewlPage=PageGetTempPageCopy(lPage);
430430
SizepageSize=PageGetPageSize(newlPage);
431-
432-
staticchartupstore[2*BLCKSZ];
431+
/*
432+
* Must have tupstore MAXALIGNed to use PG macros to access data in
433+
* it. Should not rely on compiler alignment preferences to avoid
434+
* tupstore overflow related to PG in-memory page items alignment
435+
* inside rumDataPageLeafRead() or elsewhere.
436+
*/
437+
staticchartupstoreStorage[2*BLCKSZ+MAXIMUM_ALIGNOF];
438+
char*tupstore= (char*)MAXALIGN(tupstoreStorage);
433439

434440
entryPreparePage(btree,newlPage,off);
435441

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp