pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Ran Benita <ran@unusedvar.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Broken PQtrace CopyData display
Date: Sun, 31 Aug 2025 13:53:50 +0900
Message-ID: <aLPVXkOipoBSWSb1@paquier.xyz> (raw)
In-Reply-To: <a3383211-4539-459b-9d51-95c736ef08e0@app.fastmail.com>
References: <a3383211-4539-459b-9d51-95c736ef08e0@app.fastmail.com>

On Fri, Aug 29, 2025 at 10:45:18PM +0300, Ran Benita wrote:
> I used PQtrace to trace a logical decoding session, and was confused to see
> lines like this:
> 
> 2025-08-29 22:09:57.633980	F	38	CopyData	 'r\x00\x00\x00\x00\xffffff8e\x07\xffffff85x\x00\x00\x00\x00\xffffff8e\x07\xffffff85x\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\xffffffe0\xffffff84\xffffff89R\xffffffd7\xffffffb8\x00'
> 
> The data doesn't make sense and has the wrong length. A quick look shows that
> the \xffffff85 parts are a signedness issue (on my compiler char is signed).
>
> @@ -212,7 +212,7 @@ pqTraceOutputNchar(FILE *pfdebug, int len, const char *data, int *cursor, bool s
>          else
>          {
>              fwrite(v + next, 1, i - next, pfdebug);
> -            fprintf(pfdebug, "\\x%02x", v[i]);
> +            fprintf(pfdebug, "\\x%02x", (unsigned char) v[i]);
>              next = i + 1;
>          }
>      }

Yeah.  Not a lot of people use the libpq tracing, but it would be
better to show non-printable data in a consistent way.

> The diff below fixes this particular problem, though they say bugs are like
> mushrooms, if you find one then there are probably others nearby, so a more
> comprehensive fix may be warranted.

There's one more mushroom: pqTraceOutputByte1() also uses a %02X
without a cast for non-printable data.  Note as well
logicalmsg_desc(), auth-oauth.c, mbprint.c (which uses an unsigned
char type in input to force things).
--
Michael

Attachments:

  [application/pgp-signature] signature.asc (832B, ../aLPVXkOipoBSWSb1@paquier.xyz/2-signature.asc)
  download

view thread (4+ messages)  latest in thread

Message-ID: <aLPVXkOipoBSWSb1@paquier.xyz>
Permalink:  ../aLPVXkOipoBSWSb1@paquier.xyz/
Also on:    postgresql.org/message-id/aLPVXkOipoBSWSb1@paquier.xyz

 · 

reply

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-bugs@postgresql.org
  Cc: michael@paquier.xyz, ran@unusedvar.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: Broken PQtrace CopyData display
  In-Reply-To: <aLPVXkOipoBSWSb1@paquier.xyz>

* 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