Re: BUG #17706: ALTER TYPE leads to crash

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: s(dot)shinderuk(at)postgrespro(dot)ru, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17706: ALTER TYPE leads to crash
Date: 2022-12-08 04:16:44
Message-ID: CAMbWs48beVBjLyjza3mCNzOT1qYAt9NcV=VMzeOMbCAVAXBLGg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thu, Dec 8, 2022 at 4:51 AM PG Bug reporting form <noreply(at)postgresql(dot)org>
wrote:

> With PL/pgSQL:
>
> create type foo as (a int, b int);
>
> create function bar() returns record as $$
> declare
> r foo := row(123, 2^30);
> begin
> alter type foo alter attribute b type text;
> return r;
> end;
> $$ language plpgsql;
>
> postgres=# select bar();
> server closed the connection unexpectedly
> This probably means the server terminated abnormally
> before or while processing the request.
>
> LOG: server process (PID 394076) was terminated by signal 11: Segmentation
> fault
>
> (Here 2^30 is interpreted as a string length.)

ISTM after the alter operation, the attribute description of 'b' has
been altered to cope with type text, but the data layout inside the heap
tuple stays unchanged. So when we fetch attribute 'b', what we get is
an integer pointer into the tuple's data area storing value 2^30, due to
type text is not attbyval.

Then later we interpret that integer pointer as a varlena pointer, which
is not correct.

But I'm not sure how to fix it. Is there an easy way to also alter the
data layout inside the tuple?

Thanks
Richard

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2022-12-08 05:01:08 Re: BUG #17706: ALTER TYPE leads to crash
Previous Message David G. Johnston 2022-12-07 22:52:20 Re: Bug in jsonb_path_exists (maybe _match) one-element scalar/variable jsonpath handling