Re: [PATCH v1] pg_stash_advice: Reject embedded NUL bytes in persistence files

From: Haibo Yan <tristan(dot)yim(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: [PATCH v1] pg_stash_advice: Reject embedded NUL bytes in persistence files
Date: 2026-11-18 02:35:19
Message-ID: CABXr29FaZL_Ok6T6p_yzGM_SHn2TKzDm7vb2wQ8Ne95xmScC3Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Nov 17, 2026 at 6:23 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>
>
>
> > On Nov 18, 2026, at 02:27, Haibo Yan <tristan(dot)yim(at)gmail(dot)com> wrote:
> >
> > Hi Chao,
> >
> > Thanks for reviewing. I haven't found a case where normal writes or
> > a crash left an embedded NUL in pg_stash_advice.tsv. The writer uses a
> > temporary file and durable_rename(), and SQL text input rejects NUL
> > even with SQL_ASCII. I inserted the NUL by hand for the test.
> >
> > Other byte changes can go undetected. NUL is worth checking because
> > the loader mistakes it for EOF, reports success, and can discard the
> > remaining records on the next save.
> >
> > Best regards,
> > Haibo
>
> If this is defensive handling of a manually corrupted file, then the same concern may apply to many other text file readers. In that case, instead of adding a check specifically for the stash file, maybe a better way is to add a generic text file reader to handle all possible errors in a single place.
>
> Best regards,
> --
> Chao Li (Evan)
> HighGo Software Co., Ltd.
> https://www.highgo.com/
>
>
>
Hi Chao,

Thanks for the suggestion. A shared helper could make sense if several
readers need the same checks. Some parsers can detect NUL as they parse,
so I'd avoid requiring a separate scan in a generic reader.

The stash loader already reads the whole file into memory. A memchr()
check on that buffer prevents it from treating an embedded NUL as EOF
and accepting just the prefix. I'd keep the check here for now and
revisit sharing it once we have another reader with the same needs.

Best regards,
Haibo

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2026-11-18 02:37:51 Re: Incremental Sort crash on a rescan that becomes bounded
Previous Message Tom Lane 2026-11-18 02:24:50 Re: create .abi-compliance-history file for v19