Re: BUG #13680: PostgreSQL backend process crashes on jsonb_object_agg() in plpgsql recursive function - Mailing list pgsql-bugs

From Michael Paquier
Subject Re: BUG #13680: PostgreSQL backend process crashes on jsonb_object_agg() in plpgsql recursive function
Date
Msg-id CAB7nPqS4ha2+d7oyTetqEMy8uLaG=n+uwK=XCPPdc+xZSSDtfA@mail.gmail.com
Whole thread Raw
In response to Re: BUG #13680: PostgreSQL backend process crashes on jsonb_object_agg() in plpgsql recursive function  (Michael Paquier <michael.paquier@gmail.com>)
Responses Re: BUG #13680: PostgreSQL backend process crashes on jsonb_object_agg() in plpgsql recursive function  (boyko yordanov <b.yordanov2@gmail.com>)
Re: BUG #13680: PostgreSQL backend process crashes on jsonb_object_agg() in plpgsql recursive function  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
On Thu, Oct 15, 2015 at 10:44 AM, Michael Paquier wrote:
> I am looking into it in more details, for now I have added an open item for 9.5.
> Regards,

This simple query reproduces the crash as well:
=# select json_object_agg(1, NULL::json);
 json_object_agg
-----------------
 { "1" : null }
(1 row)
=# select jsonb_object_agg(1, NULL::jsonb);
server closed the connection unexpectedly

It happens that jsonb_object_agg_transfn is not able to manage
correctly NULL values in the context of a JSONB value, and it seems to
me that this is caused by an oversight in datum_to_jsonb regarding the
handling of NULL values.

Attached is a patch with some regression tests for master and
REL9_5_STABLE where the bug has been introduced.
Thoughts?
--
Michael

Attachment

pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: BUG #13682: error while connecting to database
Next
From: Michael Paquier
Date:
Subject: Re: BUG #13680: PostgreSQL backend process crashes on jsonb_object_agg() in plpgsql recursive function