Aw: Re: Minor documentation error regarding streaming replication protocol - Mailing list pgsql-hackers

From Brar Piening
Subject Aw: Re: Minor documentation error regarding streaming replication protocol
Date
Msg-id trinity-b5c0c9ec-957a-42f8-9f58-cb01cd00dd39-1602743271839@3c-app-gmx-bs50
Whole thread Raw
In response to Re: Minor documentation error regarding streaming replication protocol  (Bruce Momjian <bruce@momjian.us>)
Responses Re: Aw: Re: Minor documentation error regarding streaming replication protocol
List pgsql-hackers
Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>> Good point. The reporter was assuming the data would come to the client
>> in the bytea output format specified by the GUC, e.g. \x..., so that
>> doesn't happen either. As I said before, it is more raw bytes, but we
>> don't have an SQL data type for that.

> I did some more research on this. It turns out timeline 'content' is
> the only BYTEA listed in the protocol docs, even though it just passes C
> strings to pq_sendbytes(), just like many other fields like the field
> above it, the timeline history filename. The proper fix is to change
> the code to return the timeline history file contents as TEXT instead of
> BYTEA.

In the light of what Michael wrote above, I don't think that this is really enough.

If the timeline history file can contain strings which "may not be made just of ASCII characters" this would probably
makethe client side assume that the content is being sent as TEXT encoded in client_encoding which again isn't true.
 
In the worst case this could lead to nasty decoding bugs on the client side which could even result in security
issues.

Since you probably can't tell in which encoding the aforementioned "recovery target name" was written to the timeline
historyfile, I agree with Michael that BYTEA is probably the sanest way to send this file.
 

IMO the best way out of this is to either really encode the content as BYTEA by passing it through byteaout() and by
thatescaping characters <0x20 and >0x7e, or to document that the file is being sent "as raw bytes that can be read as
'byteaEscape Format' by parsers compatible with byteain()" (this works because byteain() doesn't check whether bytes
<0x20or >0x7e are actually escaped).
 

Again, reading the raw bytes, either via byteain() or just as raw bytes, isn't really a problem and I don't want to
bringyou into a situation where the cure is worse than the disease.
 



pgsql-hackers by date:

Previous
From: Kyotaro Horiguchi
Date:
Subject: Re: Add Information during standby recovery conflicts
Next
From: "tsunakawa.takay@fujitsu.com"
Date:
Subject: RE: [Patch] Optimize dropping of relation buffers using dlist