Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZI6yO-0004nS-8w for pgsql-bugs@arkaria.postgresql.org; Thu, 23 Jul 2015 03:15:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZI6yM-000215-U9 for pgsql-bugs@arkaria.postgresql.org; Thu, 23 Jul 2015 03:15:02 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZI6yL-00020u-BF for pgsql-bugs@postgresql.org; Thu, 23 Jul 2015 03:15:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZI6yI-00072t-S0 for pgsql-bugs@postgresql.org; Thu, 23 Jul 2015 03:15:00 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t6N3ErOa026930; Wed, 22 Jul 2015 23:14:53 -0400 From: Tom Lane To: b.yordanov2@gmail.com cc: pgsql-bugs@postgresql.org, Andrew Dunstan Subject: Re: BUG #13514: PostgreSQL backend process crashes on jsonb_object_agg() In-reply-to: <20150722143933.9710.39668@wrigleys.postgresql.org> References: <20150722143933.9710.39668@wrigleys.postgresql.org> Comments: In-reply-to b.yordanov2@gmail.com message dated "Wed, 22 Jul 2015 14:39:33 -0000" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <26886.1437621191.0@sss.pgh.pa.us> Date: Wed, 22 Jul 2015 23:14:53 -0400 Message-ID: <26929.1437621293@sss.pgh.pa.us> X-Pg-Spam-Score: -3.1 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26886.1437621191.1@sss.pgh.pa.us> b.yordanov2@gmail.com writes: > jsonb_object_agg() appears to fail when the second argument (in this case > attributes->z->'tt') is a nonexistent jsonb column (there is > attributes->z->'t' but not 'tt'). Seems to be failure to handle nulls properly. The attached patch stops the crash for me, but I've not checked to see if the results are "right", nor scouted around to see if there are similar bugs nearby. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="jsonb-nulls-crash.patch"; charset="us-ascii" Content-ID: <26886.1437621191.2@sss.pgh.pa.us> Content-Description: jsonb-nulls-crash.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c index e689722..b82bde0 100644 *** a/src/backend/utils/adt/jsonb.c --- b/src/backend/utils/adt/jsonb.c *************** jsonb_agg_transfn(PG_FUNCTION_ARGS) *** 1606,1612 **** =20=20 memset(&elem, 0, sizeof(JsonbInState)); =20=20 ! datum_to_jsonb(val, false, &elem, tcategory, outfuncoid, false); =20=20 jbelem =3D JsonbValueToJsonb(elem.res); =20=20 --- 1606,1612 ---- =20=20 memset(&elem, 0, sizeof(JsonbInState)); =20=20 ! datum_to_jsonb(val, PG_ARGISNULL(1), &elem, tcategory, outfuncoid, false= ); =20=20 jbelem =3D JsonbValueToJsonb(elem.res); =20=20 *************** jsonb_object_agg_transfn(PG_FUNCTION_ARG *** 1759,1765 **** =20=20 memset(&elem, 0, sizeof(JsonbInState)); =20=20 ! datum_to_jsonb(val, false, &elem, tcategory, outfuncoid, true); =20=20 jbkey =3D JsonbValueToJsonb(elem.res); =20=20 --- 1759,1765 ---- =20=20 memset(&elem, 0, sizeof(JsonbInState)); =20=20 ! datum_to_jsonb(val, PG_ARGISNULL(1), &elem, tcategory, outfuncoid, true); =20=20 jbkey =3D JsonbValueToJsonb(elem.res); =20=20 *************** jsonb_object_agg_transfn(PG_FUNCTION_ARG *** 1777,1783 **** =20=20 memset(&elem, 0, sizeof(JsonbInState)); =20=20 ! datum_to_jsonb(val, false, &elem, tcategory, outfuncoid, false); =20=20 jbval =3D JsonbValueToJsonb(elem.res); =20=20 --- 1777,1783 ---- =20=20 memset(&elem, 0, sizeof(JsonbInState)); =20=20 ! datum_to_jsonb(val, PG_ARGISNULL(2), &elem, tcategory, outfuncoid, false= ); =20=20 jbval =3D JsonbValueToJsonb(elem.res); =20=20 ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs ------- =_aaaaaaaaaa0--