Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WHmOq-0006cE-SI for pgsql-bugs@arkaria.postgresql.org; Mon, 24 Feb 2014 03:40:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WHmOq-0004O5-C4 for pgsql-bugs@arkaria.postgresql.org; Mon, 24 Feb 2014 03:40:12 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WHmOp-0004NR-J0 for pgsql-bugs@postgresql.org; Mon, 24 Feb 2014 03:40:11 +0000 Received: from mail-pb0-f51.google.com ([209.85.160.51]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WHmOm-0001c2-Q2 for pgsql-bugs@postgresql.org; Mon, 24 Feb 2014 03:40:10 +0000 Received: by mail-pb0-f51.google.com with SMTP id un15so5969889pbc.38 for ; Sun, 23 Feb 2014 19:40:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:content-type:mime-version; bh=916yJXFA2zVz8De2EpPC6PrAwRf6wc7VeSEyEtEq6uA=; b=IWGztZoi1tHawDpNyXOVwTp0aJlXJDv+dhnMEuw34Y1qczfBKM/6+xJnj9SBsroPt+ wdvJqy2Bu9yZlU/Yw4I+jCoOKYKGsqEOJkyPkzbclgUpB3OzyGob8mTkej30mkQnn2dw pus8DFJ1nZ3iuWTcwlkeqGqystQtiBPGfAptn0bLmNXhzd/9zJQezQ0+KvG8zzWT1DAC fYoQEqOpQpJKkKz9G7JaykT69acU3f5dqrjgBGalsAFiKaQkDsHoWALeAroNUMPrLLI8 pVIhW6tZIEJ5jHDSEt/3yJjh1q7KycI5T7f4ARpg+xkHZYDTOf4r/GhS7MS6TfRyKPSC mEPw== X-Gm-Message-State: ALoCoQn9KCb/lFMjPEqbVhuOOs3o9lrqkh135a1tTrb275wBBF/crQMWP0xP+5TMbgtTqIaW6arH X-Received: by 10.66.248.227 with SMTP id yp3mr22132870pac.116.1393213207099; Sun, 23 Feb 2014 19:40:07 -0800 (PST) Received: from [192.168.0.105] (c-69-181-249-16.hsd1.ca.comcast.net. [69.181.249.16]) by mx.google.com with ESMTPSA id dc4sm2558296pbc.34.2014.02.23.19.40.05 for (version=SSLv3 cipher=RC4-SHA bits=128/128); Sun, 23 Feb 2014 19:40:05 -0800 (PST) Message-ID: <1393213204.17606.6.camel@jdavis> Subject: Re: Crash in json_to_record() From: Jeff Davis To: pgsql-bugs@postgresql.org Date: Sun, 23 Feb 2014 19:40:04 -0800 In-Reply-To: <1391797441.15160.41.camel@jdavis> References: <1391797441.15160.41.camel@jdavis> Content-Type: multipart/mixed; boundary="=-yPojdaYJIbv3+RcOn3f5" X-Mailer: Evolution 3.8.4-0ubuntu1 Mime-Version: 1.0 X-Pg-Spam-Score: -2.6 (--) 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 --=-yPojdaYJIbv3+RcOn3f5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit On Fri, 2014-02-07 at 10:24 -0800, Jeff Davis wrote: > The attached script crashes on master. It looks like it assumes > get_call_result_type() always returns a non-NULL tupdesc. Proposed patch attached; will commit soon unless someone objects. Checking that get_call_result_type() returns TYPEFUNC_COMPOSITE seems to be the convention for ensuring the tupdesc is set. I changed the 3 call sites that do not currently follow that convention (all in jsonfuncs.c). The other two call sites don't seem to be real problems, but following the convention seems best. For the one call site that actually is a problem, I added a HINT to suggest calling the function from the FROM clause. Regards, Jeff Davis --=-yPojdaYJIbv3+RcOn3f5 Content-Disposition: attachment; filename="json.patch" Content-Type: text/x-patch; name="json.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit *** a/src/backend/utils/adt/jsonfuncs.c --- b/src/backend/utils/adt/jsonfuncs.c *************** *** 941,947 **** each_worker(PG_FUNCTION_ARGS, bool as_text) rsi->returnMode = SFRM_Materialize; ! (void) get_call_result_type(fcinfo, NULL, &tupdesc); /* make these in a sufficiently long-lived memory context */ old_cxt = MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory); --- 941,951 ---- rsi->returnMode = SFRM_Materialize; ! if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) ! ereport(ERROR, ! (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), ! errmsg("function returning record called in context " ! "that cannot accept type record"))); /* make these in a sufficiently long-lived memory context */ old_cxt = MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory); *************** *** 1349,1355 **** populate_record_worker(PG_FUNCTION_ARGS, bool have_record_arg) json = PG_GETARG_TEXT_P(0); ! get_call_result_type(fcinfo, NULL, &tupdesc); } json_hash = get_json_object_as_hash(json, "json_populate_record", --- 1353,1365 ---- json = PG_GETARG_TEXT_P(0); ! if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) ! ereport(ERROR, ! (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), ! errmsg("function returning record called in context " ! "that cannot accept type record"), ! errhint("Try calling the function in the FROM clause " ! "using a column definition list."))); } json_hash = get_json_object_as_hash(json, "json_populate_record", *************** *** 1713,1719 **** populate_recordset_worker(PG_FUNCTION_ARGS, bool have_record_arg) * get the tupdesc from the result set info - it must be a record type * because we already checked that arg1 is a record type. */ ! (void) get_call_result_type(fcinfo, NULL, &tupdesc); state = palloc0(sizeof(PopulateRecordsetState)); sem = palloc0(sizeof(JsonSemAction)); --- 1723,1733 ---- * get the tupdesc from the result set info - it must be a record type * because we already checked that arg1 is a record type. */ ! if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) ! ereport(ERROR, ! (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), ! errmsg("function returning record called in context " ! "that cannot accept type record"))); state = palloc0(sizeof(PopulateRecordsetState)); sem = palloc0(sizeof(JsonSemAction)); --=-yPojdaYJIbv3+RcOn3f5 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 --=-yPojdaYJIbv3+RcOn3f5--