Re: BUG #17798: Incorrect memory access occurs when using BEFORE ROW UPDATE trigger

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Alexander Lakhin <exclusion(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17798: Incorrect memory access occurs when using BEFORE ROW UPDATE trigger
Date: 2023-04-19 08:29:08
Message-ID: CAMbWs48FHhuuuWbxygO4Wey7ahdaSwRjzJODKXx7=GFsge_aLg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Apr 3, 2023 at 2:29 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:

> Reproduced this issue on master with your queries. I looked into this
> issue and I agree with your analysis. I think this is exactly what
> happened.
>
> I also agree that we should materialize the newslot before we fetch
> trigtuple from the oldslot which would materialize the oldslot and
> release all buffer pins. But I'm not too familiar with the arounding
> codes so need someone else to have a look.
>

I have a second look at this issue and now I think the fix in v1 patch
is correct. I think the comment needs to be updated for this change,
maybe something like

* (Typically, newslot was also generated by ExecGetUpdateNewTuple, so
* that epqslot_clean will be that same slot and the copy step below
- * is not needed.)
+ * is not needed. And we need to materialize newslot in this case,
+ * since its tuple might be dependent on oldslot's storage, which
+ * might not be a local copy and be freed before we fetch newslot's
+ * tuple.)

Thanks
Richard

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruno Bonfils 2023-04-19 09:35:29 About #13489
Previous Message Tom Lane 2023-04-18 15:25:42 Re: BUG #17847: Unaligned memory access in ltree_gist