Re: BUG #19899: PL/Python backend crashes (SIGSEGV) when converting a column value to a Python object fails

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: marcos(dot)castedo(at)anachronics(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19899: PL/Python backend crashes (SIGSEGV) when converting a column value to a Python object fails
Date: 2026-11-16 17:53:35
Message-ID: 121695.1794851615@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> When the conversion of a column value to a Python object fails inside
> Python, the backend
> terminates with signal 11 and the postmaster restarts all sessions. The
> expected result is an ERROR
> in the calling session.

The immediate cause in this example seems to be
(1) PyBytes_FromStringAndSize returns NULL after a malloc failure
(2) We blindly pass that NULL to PyDict_SetItemString
(3) PyDict_SetItemString doesn't cope with that and dumps core.

It looks to me like plpy_typeio.c is just full of bugs like this,
because it doesn't have any coherent strategy for detecting or
dealing with failures. There are a few places that check for
NULL results and throw PLy_elog(ERROR), but not many. I think
we'd first want to decide whether to check immediately after
each call to a Python function, or try to centralize it a bit.

I wonder now about the rest of plpython, too.

I don't care enough about PL/Python to work on this myself,
but perhaps someone else will pick it up.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Melanie Plageman 2026-11-16 18:13:18 Re: PostgreSQL 18.6/17.11: standby PANIC on restart after VM truncation
Previous Message shihao zhong 2026-11-16 17:10:08 Re: PostgreSQL 18.6/17.11: standby PANIC on restart after VM truncation