Re: PostgreSQL 18 beta1 - Segmentation fault on custom type casting

Aleksander Alekseev <aleksander@tigerdata.com>

From: Aleksander Alekseev <aleksander@tigerdata.com>
To: pgsql-bugs@lists.postgresql.org
Cc: Thomas Thai <thomas.t.thai@gmail.com>
Date: 2025-07-10T10:59:23Z
Lists: pgsql-bugs
Hi,

> PostgreSQL 18 beta crashes with a segmentation fault when casting strings to custom types. The crash occurs specifically in PostgreSQL's type-casting system, not in extension code.
> [...]

The provided code is wrong. It doesn't work with PG17 either.

``
eax=# SELECT create_simple_type('test');
NOTICE:  create_simple_type: Creating SimpleType with value 'test'
NOTICE:  create_simple_type: About to return pointer 0x57ec7ef80018
with value 'test'
server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
```

The reason apparently is that you are not using the varlena header.
Take a look at Jsonb implementation as an example,
src/include/utils/jsonb.h