RE: START_REPLICATION silently truncates an overlong LSN component

From: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
To: 'Fujii Masao' <masao(dot)fujii(at)gmail(dot)com>
Cc: Jan Nidzwetzki <jan(at)planetscale(dot)com>, Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>, ♂π≌26218 <1991230470(at)qq(dot)com>, pgsql-bugs <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: RE: START_REPLICATION silently truncates an overlong LSN component
Date: 2026-10-26 07:26:27
Message-ID: OS7PR01MB18317955E3D7441FB5BEDC77FF5612@OS7PR01MB18317.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi Fujii-san,

Thanks for reviewing!

>
> + if (fscanf(lfp,
> + "START WAL LOCATION: %" CppAsString2(MAXPG_LSNLEN)
> "[0-9A-Fa-f/]
> (file %08X%16s)%c",
>
> For portability, isn't it better to use [0123456789ABCDEFabcdef/] instead of
> [0-9A-Fa-f/]? pg_parse_lsn() also lists the hexadecimal digits explicitly.

Done. I checked the C standard and the behavior when - is in the bracket seemed
to be the implementation-defined.

> Since we only need to detect an incremental backup here and don't use
> the LSN value, how about using "%s\n" instead of "[0-9A-Fa-f/]\n"? This would
> preserve the rejection of the above input while also rejecting malformed
> values such as "INCREMENTAL FROM LSN: junk".

Indeed, but %s cannot be used as-is because we need to pass the fixed-length char
array. If we do not have to take care the format of string, isn't it enough to
only check the prefix? I implemented like that in v6.

Best regards,
Hayato Kuroda
FUJITSU LIMITED

Attachment Content-Type Size
v6-0001-Use-pg_parse_lsn-for-reading-backup-label.patch application/octet-stream 4.0 KB
v6-0002-Add-fuzzy-test.patch application/octet-stream 4.4 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Andrey Rachitskiy 2026-10-26 08:27:28 Re: BUG #19796: io_uring crashes with specific kernel/liburing versions + io_max_concurrency due to rings overlap
Previous Message Richard Guo 2026-10-26 07:01:52 Re: BUG #19765: Wrong result from a chain of LEFT JOINs since v16