Skip to content

PAX: Fix buffer overflow in pax rmgr desc function #1088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions contrib/pax_storage/src/cpp/storage/wal/paxc_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "storage/wal/paxc_desc.h"
#endif
#include "common/relpath.h"
#include "utils/palloc.h"

void pax_rmgr_desc(StringInfo buf, XLogReaderState *record) {
char *rec = XLogRecGetData(record);
Expand All @@ -39,31 +40,28 @@ void pax_rmgr_desc(StringInfo buf, XLogReaderState *record) {
switch (info) {
case XLOG_PAX_INSERT: {
char filename[MAX_PATH_FILE_NAME_LEN];
char *relpathPart;
size_t relpathPartSz;
char *relpath_part;
char *prefix;
int32 buffer_len;

char *rec = XLogRecGetData(record);
xl_pax_insert *xlrec = (xl_pax_insert *)rec;

Assert(xlrec->target.file_name_len < MAX_PATH_FILE_NAME_LEN);
memcpy(filename, rec + SizeOfPAXInsert, xlrec->target.file_name_len);
filename[xlrec->target.file_name_len] = '\0';

relpathPart = relpathbackend(xlrec->target.node, InvalidBackendId, MAIN_FORKNUM);
relpathPartSz = strlen(relpathPart);
relpath_part = relpathbackend(xlrec->target.node, InvalidBackendId, MAIN_FORKNUM);
prefix = psprintf("%s_pax", relpath_part);
pfree(relpath_part);

memcpy(filename, relpathPart, relpathPartSz);

#define PAX_DIR_SUFFIX "_pax/"

memcpy(filename + relpathPartSz, PAX_DIR_SUFFIX, strlen(PAX_DIR_SUFFIX));
memcpy(filename + relpathPartSz + strlen(PAX_DIR_SUFFIX), rec + SizeOfPAXInsert, xlrec->target.file_name_len);
filename[relpathPartSz + xlrec->target.file_name_len + strlen(PAX_DIR_SUFFIX)] = '\0';

int32 bufferLen = XLogRecGetDataLen(record) - SizeOfPAXInsert -
buffer_len = XLogRecGetDataLen(record) - SizeOfPAXInsert -
xlrec->target.file_name_len;
appendStringInfo(buf,
"PAX_INSERT, filename = %s, offset = %ld, "
"PAX_INSERT, filename = %s/%s, offset = %ld, "
"dataLen = %d",
filename, xlrec->target.offset, bufferLen);
prefix, filename, xlrec->target.offset, buffer_len);
pfree(prefix);
break;
}
case XLOG_PAX_CREATE_DIRECTORY: {
Expand Down
2 changes: 2 additions & 0 deletions contrib/pax_storage/src/test/regress/parallel_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ test: transactions
# ----------
# Another group of parallel tests
# ----------
test: disable_autovacuum
test: privileges init_privs security_label collate lock replica_identity rowsecurity object_address tablesample groupingsets drop_operator password identity appendonly_sample aocs_sample
test: enable_autovacuum

test: matview
# ignore reason:
Expand Down
Loading