Re: process crash when a plpython function returns unicode

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Zac <zaccheob(at)inwind(dot)it>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: process crash when a plpython function returns unicode
Date: 2005-06-15 19:11:06
Message-ID: 20050615191106.GA59738@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Wed, Jun 15, 2005 at 02:29:27PM +0200, Zac wrote:

> if you define a plpythonu function that returns a unicode python string
> the server process crashes calling that function.

The crash happens if the Unicode string has the high bit set. For
example, u'\x7f' doesn't cause a crash, but u'\x80' does. Here's
a stack trace from HEAD and Python 2.4.1:

#0 0xfec6967c in PyString_AsString (op=0x0) at Objects/stringobject.c:698
#1 0xfed76a38 in PLy_function_handler (fcinfo=0xffbfde28, proc=0x47c610)
at plpython.c:777
#2 0xfed77df4 in plpython_call_handler (fcinfo=0xffbfde28) at plpython.c:352

Lines 776-77 in plpython.c are:

plrv_so = PyObject_Str(plrv);
plrv_sc = PyString_AsString(plrv_so);

PyObject_Str() is documented to return NULL on failure:

http://www.python.org/doc/2.4.1/api/object.html

Apparently PyString_AsString() isn't expecting a NULL argument, so
the code should probably check the return value of PyObject_Str()
before calling PyString_AsString().

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Carsten Sommer 2005-06-16 12:27:56 [postgres] dblink für Postgres
Previous Message Bruce Momjian 2005-06-15 16:00:57 Re: fmgr.c: In function `fmgr_info_cxt':,fmgr.c:161: internal

Browse pgsql-hackers by date

  From Date Subject
Next Message Oleg Bartunov 2005-06-15 19:16:34 Re: Gist Recovery testing
Previous Message Bruce Momjian 2005-06-15 18:45:18 Re: Add PG version number to NLS files