| From: | Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com> |
|---|---|
| To: | haogangmao(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Cc: | David Rowley <dgrowleyml(at)gmail(dot)com> |
| Subject: | Re: BUG #19466: Server crash (SIGSEGV) when FETCH after ALTER TYPE during open cursor |
| Date: | 2026-04-27 05:37:43 |
| Message-ID: | CAJTYsWUJRkCEopx07tSMX8MGcxzf0CJQh3di2XhetquzdiiVOQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi,
On Sat, 25 Apr 2026 at 15:45, Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
wrote:
> Hi,
>
> On Sat, 25 Apr 2026 at 14:34, PG Bug reporting form <
> noreply(at)postgresql(dot)org> wrote:
>
>> The following bug has been logged on the website:
>>
>> Summary:
>> PostgreSQL crashes with SIGSEGV when a cursor is open over a composite
>> type and the type is modified via ALTER TYPE during the same transaction,
>> followed by a second FETCH.
>>
>> Reproduction steps (minimal):
>> CREATE TYPE foo AS (a INT, b INT);
>> BEGIN;
>> DECLARE c CURSOR FOR
>> SELECT (i, power(2, 30))::foo
>> FROM generate_series(1,10) i;
>> FETCH c;
>> ALTER TYPE foo ALTER ATTRIBUTE b TYPE TEXT;
>> FETCH c;
>> COMMIT;
>>
>> Expected: Error message (type modified during active cursor)
>> Actual: Server process terminated with signal 11 (Segmentation fault)
>>
>> Server log:
>> client backend (PID 85) was terminated by signal 11: Segmentation fault
>> Failed process was running: [above SQL]
>>
>
>
> I confirmed the crash on master and traced the root cause. EEOP_ROW was the
> only rowtype-aware expression step that cached its TupleDesc at init
> time without an ExprEvalRowtypeCache guard. When ALTER TYPE changes
> an attribute's storage properties (e.g. int to text), the stale
> descriptor leads to SIGSEGV.
>
>
I looked through nearby rowtype-producing paths and found a few more cases
with the same general shape, so I split the proposed fix into two patches:
0001: Detect row type changes in EEOP_ROW expressions
EEOP_ROW was caching the target composite type's TupleDesc at executor
startup and never re-checking it. The patch stores the TypeCacheEntry
pointer and tupDesc_identifier for named composite row results, then
compares the identifier in ExecEvalRow() before forming the composite
Datum. If the type changed, the cursor now reports:
ERROR: row type <type-name> has changed
instead of producing a malformed Datum that can later crash the backend.
0002: Detect row type changes in additional composite result paths
While checking for similar stale TupleDesc reuse, I found the same kind
of guard is also needed for:
- whole-row Vars returning a named composite type
- SQL-language functions returning a whole named composite result
- targetlist SRFs returning named composite results
The second patch adds the same typcache TupleDesc identity check in
those paths and adds regression coverage for cursor/ALTER TYPE/FETCH
cases that previously crashed or could reuse stale layout information.
With these patches, the original repro and the additional repro cases fail
cleanly with "row type ... has changed" errors, and the backend remains
running.
Thoughts?
Regards,
Ayush
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Detect-row-type-changes-in-EEOP_ROW-expressions 2.patch | application/octet-stream | 5.1 KB |
| v1-0002-Detect-row-type-changes-in-additional-rowtype-result-paths 1.patch | application/octet-stream | 16.0 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | PG Bug reporting form | 2026-04-27 06:44:56 | BUG #19467: Inconsistency in MOD() result involving POWER() and floating-point precision in PostgreSQL |
| Previous Message | Michael Paquier | 2026-04-26 22:43:51 | Re: to_date()/to_timestamp() silently accept month=0 and day=0 |