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

Commit1db12da

Browse files
committed
Fix unaligned memory access in xlog parsing due to replication origin patch.
ParseCommitRecord() accessed xl_xact_origin directly. But the chunks inthe commit record's data only have 4 byte alignment, whereasxl_xact_origin's members require 8 byte alignment on someplatforms. Update comments to make not of that and copy the record tostack local storage before reading.With help from Stefan Kaltenbrunner in pinning down the buildfarm andverifying the fix.
1 parent484a848 commit1db12da

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

‎src/backend/access/rmgrdesc/xactdesc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,13 @@ ParseCommitRecord(uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *pars
104104

105105
if (parsed->xinfo&XACT_XINFO_HAS_ORIGIN)
106106
{
107-
xl_xact_origin*xl_origin= (xl_xact_origin*)data;
107+
xl_xact_originxl_origin;
108108

109-
parsed->origin_lsn=xl_origin->origin_lsn;
110-
parsed->origin_timestamp=xl_origin->origin_timestamp;
109+
/* we're only guaranteed 4 byte alignment, so copy onto stack */
110+
memcpy(&xl_origin,data,sizeof(xl_origin));
111+
112+
parsed->origin_lsn=xl_origin.origin_lsn;
113+
parsed->origin_timestamp=xl_origin.origin_timestamp;
111114

112115
data+=sizeof(xl_xact_origin);
113116
}

‎src/include/access/xact.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ typedef struct xl_xact_assignment
173173
* by a set XLOG_XACT_HAS_INFO bit in the xl_info field.
174174
*
175175
* NB: All the individual data chunks should be sized to multiples of
176-
* sizeof(int) and only require int32 alignment.
176+
* sizeof(int) and only require int32 alignment. If they require bigger
177+
* alignment, they need to be copied upon reading.
177178
*/
178179

179180
/* sub-records for commit/abort */
@@ -237,7 +238,7 @@ typedef struct xl_xact_commit
237238
/* xl_xact_relfilenodes follows if XINFO_HAS_RELFILENODES */
238239
/* xl_xact_invals follows if XINFO_HAS_INVALS */
239240
/* xl_xact_twophase follows if XINFO_HAS_TWOPHASE */
240-
/* xl_xact_origin follows if XINFO_HAS_ORIGIN */
241+
/* xl_xact_origin follows if XINFO_HAS_ORIGIN, stored unaligned! */
241242
}xl_xact_commit;
242243
#defineMinSizeOfXactCommit (offsetof(xl_xact_commit, xact_time) + sizeof(TimestampTz))
243244

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp