Add null termination to string received in parallel apply worker - Mailing list pgsql-hackers

From Zhijie Hou (Fujitsu)
Subject Add null termination to string received in parallel apply worker
Date
Msg-id OS0PR01MB5716FAB36CB02B0A4C58F5C594CCA@OS0PR01MB5716.jpnprd01.prod.outlook.com
Whole thread Raw
Responses Re: Add null termination to string received in parallel apply worker
Re: Add null termination to string received in parallel apply worker
Re: Add null termination to string received in parallel apply worker
List pgsql-hackers
Hi,

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.

So, here is patch to use the standard StringInfo API to store the string while
ensuring the addition of null termination. This can also resolve the Assert
issue raised by another patch[1] currently under discussion.

Thanks to Amit for offlist discussion regarding the analysis and
fix.

[1] https://www.postgresql.org/message-id/CAApHDvp6J4Bq9%3Df36-Z3mNWTsmkgGkSkX1Nwut%2BxhSi1aU8zQg%40mail.gmail.com

Best Regards,
Hou Zhijie


Attachment

pgsql-hackers by date:

Previous
From: "Drouvot, Bertrand"
Date:
Subject: Re: Add a new BGWORKER_BYPASS_ROLELOGINCHECK flag
Next
From: Peter Eisentraut
Date:
Subject: Re: Pre-proposal: unicode normalized text