Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1krJtQ-0004Dr-QK for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Dec 2020 12:02:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1krJtP-0003zq-Ll for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Dec 2020 12:02:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1krJtO-0003zj-RO for pgsql-hackers@lists.postgresql.org; Mon, 21 Dec 2020 12:02:22 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1krJtM-0002D0-Af for pgsql-hackers@lists.postgresql.org; Mon, 21 Dec 2020 12:02:21 +0000 Received: from [192.168.127.1] (port=17125 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1krJtJ-000LOP-Aw for pgsql-hackers@lists.postgresql.org; Mon, 21 Dec 2020 12:02:17 +0000 Received: from localhost ([127.0.0.1]:13720 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.93.0.4 (FreeBSD)) (envelope-from ) id 1krJtI-0006KZ-Qc for pgsql-hackers@lists.postgresql.org; Mon, 21 Dec 2020 12:02:16 +0000 From: Andrew Gierth To: pgsql-hackers@lists.postgresql.org Subject: Incorrect assertion in ExecBuildAggTrans ? Message-ID: <87mty7peb3.fsf@news-spur.riddles.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (berkeley-unix) Date: Mon, 21 Dec 2020 12:02:16 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ExecBuildAggTrans has this sequence: if (pertrans->deserialfn.fn_strict) scratch.opcode = EEOP_AGG_STRICT_DESERIALIZE; else scratch.opcode = EEOP_AGG_DESERIALIZE; scratch.d.agg_deserialize.fcinfo_data = ds_fcinfo; scratch.d.agg_deserialize.jumpnull = -1; /* adjust later */ scratch.resvalue = &trans_fcinfo->args[argno + 1].value; scratch.resnull = &trans_fcinfo->args[argno + 1].isnull; ExprEvalPushStep(state, &scratch); adjust_bailout = lappend_int(adjust_bailout, state->steps_len - 1); but later on, where adjust_bailout is processed, we see this (note that EEOP_AGG_DESERIALIZE is not checked for): if (as->opcode == EEOP_JUMP_IF_NOT_TRUE) { Assert(as->d.jump.jumpdone == -1); as->d.jump.jumpdone = state->steps_len; } else if (as->opcode == EEOP_AGG_STRICT_INPUT_CHECK_ARGS || as->opcode == EEOP_AGG_STRICT_INPUT_CHECK_NULLS) { Assert(as->d.agg_strict_input_check.jumpnull == -1); as->d.agg_strict_input_check.jumpnull = state->steps_len; } else if (as->opcode == EEOP_AGG_STRICT_DESERIALIZE) { Assert(as->d.agg_deserialize.jumpnull == -1); as->d.agg_deserialize.jumpnull = state->steps_len; } else Assert(false); Seems clear to me that the assertion is wrong, and that even though a non-strict DESERIALIZE opcode might not need jumpnull filled in, the code added it to adjust_bailout anyway, so we crash out here on an asserts build. This may have been overlooked because all the builtin deserialize functions appear to be strict, but postgis has at least one non-strict one and can hit this. This could be fixed either by fixing the assert, or by not adding non-strict deserialize opcodes to adjust_bailout; anyone have any preferences? -- Andrew (irc:RhodiumToad)