pg.ddx.io pgsql-bugs@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Crash in json_to_record() 2+ messages / 1 participants [nested] [flat]
* Crash in json_to_record() @ 2014-02-07 18:24 Jeff Davis <pgsql@j-davis.com> 2014-02-24 03:40 ` Re: Crash in json_to_record() Jeff Davis <pgsql@j-davis.com> 0 siblings, 1 reply; 2+ messages in thread From: Jeff Davis @ 2014-02-07 18:24 UTC (permalink / raw) To: pgsql-bugs The attached script crashes on master. It looks like it assumes get_call_result_type() always returns a non-NULL tupdesc. Regards, Jeff Davis -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs Attachments:^ permalink raw reply [nested|flat] 2+ messages in threadcrash.sql (text/x-sql, 164B) download
drop table t; create table t(j json); insert into t values('{"a": 1, "b": "two", "c": [1,2,3], "d": {"x": "X", "y": "Y"}}'); select json_to_record(j, true) from t;
* Re: Crash in json_to_record() 2014-02-07 18:24 Crash in json_to_record() Jeff Davis <pgsql@j-davis.com> @ 2014-02-24 03:40 ` Jeff Davis <pgsql@j-davis.com> 0 siblings, 0 replies; 2+ messages in thread From: Jeff Davis @ 2014-02-24 03:40 UTC (permalink / raw) To: pgsql-bugs 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 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs Attachments:^ permalink raw reply [nested|flat] 2+ messages in threadjson.patch (text/x-patch, 2.4K) download
*** 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));
end of thread, other threads:[~2014-02-24 03:40 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2014-02-07 18:24 Crash in json_to_record() Jeff Davis <pgsql@j-davis.com> 2014-02-24 03:40 ` Jeff Davis <pgsql@j-davis.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox