Re: Add null termination to string received in parallel apply worker

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Add null termination to string received in parallel apply worker
Date: 2023-10-11 12:26:01
Message-ID: CAA4eK1LpML__AiKVewRkbmA5cw1b_dMpaLRC38=G+EVKqYFSyg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Oct 11, 2023 at 12:18 PM Zhijie Hou (Fujitsu)
<houzj(dot)fnst(at)fujitsu(dot)com> wrote:
>
> The parallel apply worker didn't add null termination to the string received
> from the leader apply worker via the shared memory queue. This action doesn't
> bring bugs as it's binary data but violates the rule established in StringInfo,
> which guarantees the presence of a terminating '\0' at the end of the string.
>
> Although the original string in leader already includes the null termination,
> but we cannot just send all string including the null termination to the
> parallel worker, because that would increase the length while at the receiver
> there is still no null termination at data[length] which actually the length +
> 1 position.
>
> And we also cannot directly modify the received string like data[len] = '\0',
> because the data still points a shared buffer maintained by shared memory
> queue, so we'd better not modify the data outside of the string length.
>

Yeah, it may not be a good idea to modify the buffer pointing to
shared memory without any lock as we haven't reserved that part of
memory. So, we can't follow the trick used in exec_bind_message() to
maintain the convention that StringInfos have a trailing null. David,
do you see any better way to fix this case?

--
With Regards,
Amit Kapila.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2023-10-11 12:27:20 Re: SLRU optimization - configurable buffer pool and partitioning the SLRU lock
Previous Message Robert Haas 2023-10-11 12:25:12 Re: Is this a problem in GenericXLogFinish()?