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-23 03:24:43
Message-ID: OS7PR01MB1831703F6C7FD5F783A0B7F6EF5642@OS7PR01MB18317.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Dear Fujii-san,

Thanks for pushing the first half!

> + if (fscanf(lfp,
> + "CHECKPOINT LOCATION: %" CppAsString2(MAXPG_LSNLEN) "s%c", lsn,
> + &ch) != 2 ||
> + ch != '\n' ||
> + !pg_parse_lsn(lsn, checkPointLoc))
>
> This seems to accept malformed LSN fields such as:
>
> CHECKPOINT LOCATION: 0/123<NUL>junk
>
> Here, <NUL> represents an actual NUL byte. fscanf("%17s") reads past it,
> but pg_parse_lsn() sees only 0/123. The old code rejected this because %c
> read the NUL instead of a newline. START WAL LOCATION seems to
> have the same issue.

Right, it should be rejected. One my primitive fix idea is to directly specify the
acceptable strings, like [0-9A-Fa-f/]. PSA the patch.
I also attached the test code to check invalid strings can be rejected, see 0002.
I'm not intended to be pushed.

Best regards,
Hayato Kuroda
FUJITSU LIMITED

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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tender Wang 2026-10-23 03:42:10 Re: BUG #19765: Wrong result from a chain of LEFT JOINs since v16
Previous Message shihao zhong 2026-10-23 03:01:05 Re: BUG #19775: Incremental backup without data checksums restores a stale visibility map page after VACUUM truncati