From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: bogus assert in logicalmsg_desc
Date: Sun, 14 Aug 2022 18:16:53 +0200
Message-ID: <b99b6101-2f14-3796-3dfa-4a6cd7d4326d@enterprisedb.com> (raw)
Hi,
while experimenting with logical messages, I ran into this assert in
logicalmsg_desc:
Assert(prefix[xlrec->prefix_size] != '\0');
This seems to be incorrect, because LogLogicalMessage does this:
xlrec.prefix_size = strlen(prefix) + 1;
So prefix_size includes the null byte, so the assert points out at the
first payload byte. And of course, the check should be "==" because we
expect the byte to be \0, not the other way around.
It's pretty simple to make this crash by writing a logical message where
the first payload byte is \0, e.g. like this:
select pg_logical_emit_message(true, 'a'::text, '\x00'::bytea);
and then running pg_waldump on the WAL segment.
Attached is a patch addressing this. This was added in 14, so we should
backpatch to that version.
regards
--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Attachments:
[text/x-patch] logicalmsgdesc-fix.patch (642B, ../b99b6101-2f14-3796-3dfa-4a6cd7d4326d@enterprisedb.com/2-logicalmsgdesc-fix.patch)
download | inline diff:diff --git a/src/backend/access/rmgrdesc/logicalmsgdesc.c b/src/backend/access/rmgrdesc/logicalmsgdesc.cindex 099e11a84e7..08e03aa30d1 100644--- a/src/backend/access/rmgrdesc/logicalmsgdesc.c+++ b/src/backend/access/rmgrdesc/logicalmsgdesc.c@@ -28,7 +28,7 @@ logicalmsg_desc(StringInfo buf, XLogReaderState *record)
char *message = xlrec->message + xlrec->prefix_size;
char *sep = "";
- Assert(prefix[xlrec->prefix_size] != '\0');+ Assert(prefix[xlrec->prefix_size - 1] == '\0');
appendStringInfo(buf, "%s, prefix \"%s\"; payload (%zu bytes): ",
xlrec->transactional ? "transactional" : "non-transactional",
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tomas.vondra@enterprisedb.com, pgsql-hackers@lists.postgresql.org
Subject: Re: bogus assert in logicalmsg_desc
In-Reply-To: <b99b6101-2f14-3796-3dfa-4a6cd7d4326d@enterprisedb.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox