Re: BUG #17908: plpython_to_hstore() crashes with a non-dict argument

Поиск
Список
Период
Сортировка
От Dmitry Dolgov
Тема Re: BUG #17908: plpython_to_hstore() crashes with a non-dict argument
Дата
Msg-id 20230427082727.4na67kulnnlxkzq3@ddolgov.remote.csb
обсуждение исходный текст
Ответ на BUG #17908: plpython_to_hstore() crashes with a non-dict argument  (PG Bug reporting form <noreply@postgresql.org>)
Ответы Re: BUG #17908: plpython_to_hstore() crashes with a non-dict argument  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
> On Tue, Apr 25, 2023 at 01:00:02PM +0000, PG Bug reporting form wrote:
> The following bug has been logged on the website:
>
> Bug reference:      17908
> Logged by:          Alexander Lakhin
> Email address:      exclusion@gmail.com
> PostgreSQL version: 15.2
> Operating system:   Ubuntu 22.04
> Description:
>
> When executing the following query:
> CREATE EXTENSION hstore_plpython3u CASCADE;
> CREATE FUNCTION test_transform() RETURNS hstore
> LANGUAGE plpython3u
> TRANSFORM FOR TYPE hstore AS 'return "a"';
> SELECT test_transform();
>
> Here plpython_to_hstore() has got a string as an argument, but failed to
> detect that it's not a dictionary.
> With plpython2 (on REL_14_STABLE) I get:
> ERROR:  not a Python mapping
> CONTEXT:  while creating return value
> PL/Python function "test_transform"
>
> As noted in https://bugs.python.org/issue5945, the behaviour of
> PyMapping_Check() changed in Python 3, so it can't be used anymore to
> differentiate real dictionaries from strings or alike.

Thanks for finding this! That's indeed very annoying. After a quick
investigation looks like a proposed solution from [1] is to use
PyType_HasFeature with Py_TPFLAGS_MAPPING:

    -       if (!PyMapping_Check(dict))
    +       dict_type = Py_TYPE(dict);
    +       if (!PyType_HasFeature(dict_type, Py_TPFLAGS_MAPPING))

But this flag is available only starting from Python 3.10, so not
backward compatible :(

[1]: https://bugs.python.org/issue46376



В списке pgsql-bugs по дате отправления:

Предыдущее
От: Sandeep Thakkar
Дата:
Сообщение: Re: BUG #17907: PostgresSQL 15.x contains OpenSSL DLLs (vulnerable to CVE-2023-0464, CVE-2023-0465 & CVE-2023-0466)
Следующее
От: PG Bug reporting form
Дата:
Сообщение: BUG #17910: gcc-introduced load may cause concurrency bug