Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wgmhn-006OiI-2H for pgsql-bugs@arkaria.postgresql.org; Mon, 06 Jul 2026 17:02:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wgmhl-001sCi-0b for pgsql-bugs@arkaria.postgresql.org; Mon, 06 Jul 2026 17:02:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wgmhk-001sCZ-2j for pgsql-bugs@lists.postgresql.org; Mon, 06 Jul 2026 17:02:00 +0000 Received: from mail-yw1-x1130.google.com ([2607:f8b0:4864:20::1130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wgmhi-000000025sC-1jtv for pgsql-bugs@lists.postgresql.org; Mon, 06 Jul 2026 17:02:00 +0000 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-80e4455b9a3so46661297b3.1 for ; Mon, 06 Jul 2026 10:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783357316; cv=none; d=google.com; s=arc-20260327; b=rxOX6J4c65oroiotIOBMg16z6i1sGArBYMlbcPgwk9HgYRLcEQSs2J7jMP1VbIzvfk YVgKGutAxVnlXhXMipWFNow5TTlZVy2S/m1JrvUtsIeDxxzsC/Uw8Xv98SGAoUNNVgg2 W9d8DsTsBpI0YX4r3Qz9ulhNdqmkKxJdY/NtcvX3OD7eJgFnHNY8t3i/+GBzajGLo3Jv 0G9XjRPlh/Vm98WnEZ1dgNIW+BTE7Sue/r+z+VAyH+GWQMcBg+ZRCyizvPtJo3/5dPuI 3xEdSMJmH2NVir9JYYQjLizCgsuoK6f2tv78hzQ0J2TzfDEy0aapzHGwa3VllbV4SWqB Agtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ym5VsRFydu6ysYDLe/gzEtLbVMrbI6KnXQ1cR+Ff+fY=; fh=q/sM7V6zEV9mBFK6xevZf+qaKQ1bvGdccqlybF1C7qs=; b=cla3Xic26i8FJRt0nr0jRKlnM7xhmTuiTfhGYzBcpmg5XeWWHmrl6KlgleplDMEqM3 iQwIcohE5fP/ymdCkbpdG5sRjQf0vwf6WXbyas3WWle9py12MKWtLDlF7Bakiykfnje3 4P7vGsm7X06FZWClPA0Qfa4e93suu9urcB0xnLyH8mdLkWM6uqmzMo43msB3CvOs6hyp /B32gJ8HGsItq5d7+yJ3Il9++7w+XSYhYTUz5Mxelz6jGGLzL5ZhbbRFxXD3x61rJBml 6cBJYzUMz5iUTdVUm6Wax0aJh1AYixqaENmi1yYARsD7zZDxL0aBvY83tiTdIHhnsrQC 1QXQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783357316; x=1783962116; darn=lists.postgresql.org; h=content-type:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ym5VsRFydu6ysYDLe/gzEtLbVMrbI6KnXQ1cR+Ff+fY=; b=lNJ9lAGcl3vuqL1nHwa4iGcDClYRNvQs28RErCV0vSKGgfysNghXS92S2a3Z8c9WJA i/E1TzOt01uVWYod4nb4rpwFW+rcx0C/n/hHlu+5m5m5WNdQ3SG1gsChLBGEMxhdBB7E Opx1oFls2rjc9sbmbJTheOZkow3wqmnIbNFcf5Scy3DGJ6lIyv5NTCrEDdfdMvKAP6bR 6c6lvjAQ79yNsVHgRXufPAf8LqyPjqEf6LUweauoz7UfbelIK4SBU61fv9Y/WKfFQEhe p5cShjQ4eRUUCQA7azCDztEYT2R40ILtXDIpdtIzrrhrZWlbF3EupAmOzN6d59MW6d3A iiLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783357316; x=1783962116; h=content-type:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ym5VsRFydu6ysYDLe/gzEtLbVMrbI6KnXQ1cR+Ff+fY=; b=i7naOmjYgJ80tunO779MFyB/5XmVFX9yDovdreODMutkgsb0qDzwgX3oQYVi+oI4UJ VtTR8FSO5JGg5Xz0l/IpzdVkvOxGXuymrhgLZgFdoIfjKb6jVKBlD8kS59Va2JcE3drb 6N//Ju2cEf91faFZsr3vhcvenkIh/rX76AyP8gbjbPpgb0tLWp7q7fVxpwDCx2J+Iqt5 NamIqSZXxVLJEfXS2GbTfFLD1efHlVbxSStM5TpjJkCkMXD6kYaKVC52tyX6lLutIRrI 1cBpbkIvP8jVm5aSgq3w9auxLJktzHrIZOk0Z6iwMosgQ/5fij31eFx89tgEuaXwxrAn MhBA== X-Forwarded-Encrypted: i=1; AHgh+Rrll9Ov8Dwqriq5B8SloLKfY9n0Q/X3R0eNifBgvH0GjLxxprlYXCWq3vSxi5H66dpM8P92Y9eLWAGe@lists.postgresql.org X-Gm-Message-State: AOJu0YzdvI3Io5zwAQ12Cp9J0EO/7ITbweewCRR4/Ehf95oZ+rUUY5Qx 1UoaW/7kUUiEpCV2H3O7PIxKN6W4Yq4b9xQne0PqmaPkTbvh1lI5aS6+9lb9nxevxb1UNsn6UXK xbJZ1bhNOWmULrOPhhuPRBGqf8tQfRLrseosA X-Gm-Gg: AfdE7clVhICN4T4fk80DT3mYObyH2O5ilxUyRzovN/2ak3FW9kYSja5FIXQ6I1Mp+Qx SeiPdxZeuIbvG8GsK8NOUo6VBcEeddOt9LlR15BGlqpqcy9Qcn5FUk37thVyJDLcdIECQYXjfLi NJNmsN0NpBIeA3XZ2X1J9DVBc6S4WEGiTsa7HVz1Ae5GcmKH5nawR+7mLVPHus90T2d28a38E04 ydVMNiAxNHFfvxsEBKcmK6cCdg/9W8g7DKy2mhbSeAKaUkY6Tl0+akS9j3RHkqwtWpnzHaySg== X-Received: by 2002:a05:690c:c454:b0:80c:85c6:8980 with SMTP id 00721157ae682-81be3de16cdmr8347667b3.63.1783357314814; Mon, 06 Jul 2026 10:01:54 -0700 (PDT) MIME-Version: 1.0 References: <19544-a63ef569459e4e1c@postgresql.org> In-Reply-To: <19544-a63ef569459e4e1c@postgresql.org> From: Ayush Tiwari Date: Mon, 6 Jul 2026 22:31:43 +0530 X-Gm-Features: AVVi8Ccre-lUFBMJ5mXpKBnrdGvuV92bewo7BQs2OjLjd81lYKj6b3bKnF0g8zI Message-ID: Subject: Re: BUG #19544: PostgreSQL 18.3 backend crashes with SIGSEGV when a PL/pgSQL function To: haogangmao@gmail.com, pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000041d8ee0655f43b62" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000041d8ee0655f43b62 Content-Type: text/plain; charset="UTF-8" Hi, On Mon, 6 Jul 2026 at 22:21, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 19544 > Logged by: HaoGang Mao > Email address: haogangmao@gmail.com > PostgreSQL version: 18.3 > Operating system: Linux > Description: > > A PL/pgSQL function declares a local variable of composite type foo where > attribute b is INT. Inside the function, the variable is initialized with > ROW(123, power(2, 30)). The function then changes foo.b from INT to TEXT > using ALTER TYPE and returns the previously initialized composite value. > When the caller executes SELECT bar(), PostgreSQL attempts to output the > returned record using the updated composite type metadata and the backend > segfaults in the text output path. > > Reproduction steps: > > ```sql > DROP FUNCTION IF EXISTS bar(); > DROP TYPE IF EXISTS foo CASCADE; > > CREATE TYPE foo AS (a INT, b INT); > > CREATE FUNCTION bar() RETURNS RECORD AS $$ > DECLARE > r foo := ROW(123, power(2, 30)); > BEGIN > ALTER TYPE foo ALTER ATTRIBUTE b TYPE TEXT; > RETURN r; > END; > $$ LANGUAGE plpgsql; > > SELECT bar(); > ``` > > Expected behavior: > PostgreSQL should reject the operation or report an error indicating that > the composite type changed while a value of the old layout is still being > returned. > > Actual behavior: > The client connection is closed unexpectedly and the PostgreSQL backend > process terminates with SIGSEGV. > > Server log: > > ```text > LOG: client backend (PID 90) was terminated by signal 11: Segmentation > fault > DETAIL: Failed process was running: SELECT bar(); > LOG: terminating any other active server processes > LOG: all server processes terminated; reinitializing > ``` > > GDB backtrace, trimmed: > > ```text > Program received signal SIGSEGV, Segmentation fault. > #0 0x0000762a0a47fc60 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 > #1 text_to_cstring(t=0x5c9ae669d6bc) at varlena.c:234 > len = 268435452 > #2 textout(fcinfo=0x7fff0aabda20) at varlena.c:603 > #3 FunctionCall1Coll(flinfo=0x5c9ae668c148, collation=0, > arg1=101820360414908) at fmgr.c:1139 > #4 OutputFunctionCall(flinfo=0x5c9ae668c148, > val=101820360414908) at fmgr.c:1685 > #5 record_out(fcinfo=0x7fff0aabdbc0) at rowtypes.c:435 > column_type = 25 > attr = 101820360414908 > tupdesc = 0x762a00b61fd8 > ncolumns = 2 > i = 1 > #8 printtup(slot=0x5c9ae668bb88, self=0x5c9ae6699e18) at printtup.c:360 > #9 ExecutePlan(queryDesc=0x5c9ae65c3ed0, operation=CMD_SELECT, > sendTuples=true, numberTuples=0, > direction=ForwardScanDirection, dest=0x5c9ae6699e18) > at execMain.c:1742 > #12 PortalRunSelect(portal=0x5c9ae6619740, forward=true, > count=0, dest=0x5c9ae6699e18) at pquery.c:921 > #13 PortalRun(portal=0x5c9ae6619740, > count=9223372036854775807, isTopLevel=true, > dest=0x5c9ae6699e18, altdest=0x5c9ae6699e18, > qc=0x7fff0aabdfe0) at pquery.c:765 > #14 exec_simple_query(query_string=0x5c9ae6599b80 "SELECT bar();") > at postgres.c:1273 > #15 PostgresMain(dbname=0x5c9ae65d2f38 "postgres", > username=0x5c9ae65d2f20 "pguser") at postgres.c:4766 > ``` > This looks the same as [1]. Could you please check that thread, patches are posted, you may review those. I'll spend some time this week on that too. Regards, Ayush [1] https://www.postgresql.org/message-id/19382-4c2060ffee72759b%40postgresql.org --00000000000041d8ee0655f43b62 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

On Mon, 6 Jul 20= 26 at 22:21, PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the websit= e:

Bug reference:=C2=A0 =C2=A0 =C2=A0 19544
Logged by:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 HaoGang Mao
Email address:=C2=A0 =C2=A0 =C2=A0 haogangmao@gmail.com
PostgreSQL version: 18.3
Operating system:=C2=A0 =C2=A0Linux
Description:=C2=A0 =C2=A0 =C2=A0 =C2=A0

A PL/pgSQL function declares a local variable of composite type foo where attribute b is INT. Inside the function, the variable is initialized with ROW(123, power(2, 30)). The function then changes foo.b from INT to TEXT using ALTER TYPE and returns the previously initialized composite value. When the caller executes SELECT bar(), PostgreSQL attempts to output the returned record using the updated composite type metadata and the backend segfaults in the text output path.

Reproduction steps:

```sql
DROP FUNCTION IF EXISTS bar();
DROP TYPE IF EXISTS foo CASCADE;

CREATE TYPE foo AS (a INT, b INT);

CREATE FUNCTION bar() RETURNS RECORD AS $$
DECLARE
=C2=A0 =C2=A0 r foo :=3D ROW(123, power(2, 30));
BEGIN
=C2=A0 =C2=A0 ALTER TYPE foo ALTER ATTRIBUTE b TYPE TEXT;
=C2=A0 =C2=A0 RETURN r;
END;
$$ LANGUAGE plpgsql;

SELECT bar();
```

Expected behavior:
PostgreSQL should reject the operation or report an error indicating that the composite type changed while a value of the old layout is still being returned.

Actual behavior:
The client connection is closed unexpectedly and the PostgreSQL backend
process terminates with SIGSEGV.

Server log:

```text
LOG:=C2=A0 client backend (PID 90) was terminated by signal 11: Segmentatio= n
fault
DETAIL:=C2=A0 Failed process was running: SELECT bar();
LOG:=C2=A0 terminating any other active server processes
LOG:=C2=A0 all server processes terminated; reinitializing
```

GDB backtrace, trimmed:

```text
Program received signal SIGSEGV, Segmentation fault.
#0=C2=A0 0x0000762a0a47fc60 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #1=C2=A0 text_to_cstring(t=3D0x5c9ae669d6bc) at varlena.c:234
=C2=A0 =C2=A0 len =3D 268435452
#2=C2=A0 textout(fcinfo=3D0x7fff0aabda20) at varlena.c:603
#3=C2=A0 FunctionCall1Coll(flinfo=3D0x5c9ae668c148, collation=3D0,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 arg1=3D101820360414908) at fmgr.c:1139
#4=C2=A0 OutputFunctionCall(flinfo=3D0x5c9ae668c148,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0val=3D101820360414908) at fmgr.c:1685
#5=C2=A0 record_out(fcinfo=3D0x7fff0aabdbc0) at rowtypes.c:435
=C2=A0 =C2=A0 column_type =3D 25
=C2=A0 =C2=A0 attr =3D 101820360414908
=C2=A0 =C2=A0 tupdesc =3D 0x762a00b61fd8
=C2=A0 =C2=A0 ncolumns =3D 2
=C2=A0 =C2=A0 i =3D 1
#8=C2=A0 printtup(slot=3D0x5c9ae668bb88, self=3D0x5c9ae6699e18) at printtup= .c:360
#9=C2=A0 ExecutePlan(queryDesc=3D0x5c9ae65c3ed0, operation=3DCMD_SELECT, =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 sendTuples=3Dtrue, = numberTuples=3D0,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 direction=3DForward= ScanDirection, dest=3D0x5c9ae6699e18)
=C2=A0 =C2=A0 at execMain.c:1742
#12 PortalRunSelect(portal=3D0x5c9ae6619740, forward=3Dtrue,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 count= =3D0, dest=3D0x5c9ae6699e18) at pquery.c:921
#13 PortalRun(portal=3D0x5c9ae6619740,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 count=3D922337203685477580= 7, isTopLevel=3Dtrue,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dest=3D0x5c9ae6699e18, alt= dest=3D0x5c9ae6699e18,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 qc=3D0x7fff0aabdfe0) at pq= uery.c:765
#14 exec_simple_query(query_string=3D0x5c9ae6599b80 "SELECT bar();&quo= t;)
=C2=A0 =C2=A0 at postgres.c:1273
#15 PostgresMain(dbname=3D0x5c9ae65d2f38 "postgres",
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0username=3D0x= 5c9ae65d2f20 "pguser") at postgres.c:4766
```

This looks the same as [1].

Could you p= lease check that thread, patches are posted,
you may review those. I'= ;ll spend some time this week on that too.

Regards,
Ayush

= [1]=C2=A0https://www.postgresql.org/message-id/19382-4c2060f= fee72759b%40postgresql.org
--00000000000041d8ee0655f43b62--