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 1ptpc3-0001qv-1C for pgsql-bugs@arkaria.postgresql.org; Tue, 02 May 2023 13:00:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ptpc0-0001CS-7w for pgsql-bugs@arkaria.postgresql.org; Tue, 02 May 2023 13:00:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ptpbz-0001CJ-VJ for pgsql-bugs@lists.postgresql.org; Tue, 02 May 2023 13:00:07 +0000 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1ptpbx-0008V6-9U for pgsql-bugs@lists.postgresql.org; Tue, 02 May 2023 13:00:07 +0000 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4eff055d4d3so4524898e87.3 for ; Tue, 02 May 2023 06:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683032404; x=1685624404; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=CWaHTeuqlcjhEezOcTxIX386w3aXkxavxm6+Nf6MlN8=; b=hiU/hHso5gb5NbOab0hOzehIqoPG4UE0FHDF57mBJC6fWZj204x1qLwtXDKD76uozW SxWp4yrpKGZP0frjjHg+1p/OMTo7rTmSIunkJBZVfpDnbDXZkvAhjNYQrburjulnKA+2 RZpze74UXx4ry6FLsDSPYgjO3utWus98N6bAoXcNAw9TQvnZfmHKZL2EEWhfXg8502hN wJa/xaqVmwd69PPdA8pVZSy0GZnoPmB92MMlhSKZTuCrPTUpvvhI/yxF+YmP+Ku1tL1q VTRgCrVxSPXWhAO92usIfHssyKfEjB0+BL53WldTXlMuzP8BObWDJuGb+LFzRPFjOj8+ YFwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683032404; x=1685624404; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CWaHTeuqlcjhEezOcTxIX386w3aXkxavxm6+Nf6MlN8=; b=W5RYol/UD5aJO+Rmo4O7dXQ0PJ2nzfd+b7xbOl8gZOTEWYcnvqc+I9//03Ao+p5CCX JIYTtb18gDko0iXquAbyvr9BqOhNhx1DQAwyz9DQrGCYy8vnewihUmAjmBu2R8PM/gyD Z+UhZMw4dEioiCnCaoxv6UgYRWVhtmtHNcLSCtfYTlfDDm8uEP/HXRTZhr43tiLYxM4j 2ZgEl2Bjl1pF74FbkabWjnbP9eoP9IzCg3i+iNpP1uroLthvNWbL1gq9IxukiiElcGfB 80AMGQf/HLoxulBqHQk5NaBfYBpyqdCXcpnKdwySfKrJIJfWT7kCT/yFN443VWCM2/pR xQFQ== X-Gm-Message-State: AC+VfDyKqtiIVkHzWnNue6bJuI8fHjNvRP9c8IfY5cg672kFlzmMmtgC Zz0CnjLSOiJ8HfonbagATtk= X-Google-Smtp-Source: ACHHUZ5cHSS1Ega8ZTT1YXcSUNa9shxV8Ht7bh35EL39UykZJCgZsBcXNfBPLpSkECnMBguQTQVWhw== X-Received: by 2002:ac2:494f:0:b0:4f0:80:d0bf with SMTP id o15-20020ac2494f000000b004f00080d0bfmr4473970lfi.5.1683032403553; Tue, 02 May 2023 06:00:03 -0700 (PDT) Received: from [1.0.0.7] ([178.155.28.115]) by smtp.gmail.com with ESMTPSA id f16-20020ac25090000000b004efee4ff266sm4354282lfm.67.2023.05.02.06.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 May 2023 06:00:02 -0700 (PDT) Message-ID: <9f23591c-610a-60d4-2b29-26a860f7c3a8@gmail.com> Date: Tue, 2 May 2023 16:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: BUG #17798: Incorrect memory access occurs when using BEFORE ROW UPDATE trigger Content-Language: en-US To: Tom Lane Cc: Peter Geoghegan , pgsql-bugs@lists.postgresql.org, Richard Guo , Andres Freund References: <17798-0907404928dcf0dd@postgresql.org> <87fe6c28-80b2-f709-a8db-d105e5240e39@gmail.com> <1849610.1682807087@sss.pgh.pa.us> <88b5750f-a5da-798b-e5a1-af2c3ecb9b60@gmail.com> <2155320.1682913887@sss.pgh.pa.us> From: Alexander Lakhin In-Reply-To: <2155320.1682913887@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 01.05.2023 07:04, Tom Lane wrote: > Alexander Lakhin writes: >> So I'm going to start it over and find a repro that will show something >> interesting without Valgrind (and let estimate the probability of a >> problem in the field). > I think a probability estimate is not all that exciting: "it's low > but not zero" is sufficient information to act on. What I am curious > about is how come 86dc90056's changes triggered a visible problem. > Understanding that might give us a better feel for what is the real > structural issue here --- which I'm worried about because I have > little confidence that there aren't similar bugs lurking in other > code paths. I've found one significant difference between old and new code paths. On 86dc90056 I see the following call chain: ExecGetUpdateNewTuple(planSlot = epqslot_candidate, oldSlot = oldslot): econtext->ecxt_scantuple = oldSlot; -> internalGetUpdateNewTuple() -> ExecProject(projInfo=relinfo->ri_projectNew) -> ExecEvalExprSwitchContext(state=projInfo->pi_state, econtext=projInfo->pi_exprContext) -> state->evalfunc(state, econtext, isNull); -> ExecInterpExpr(): scanslot = econtext->ecxt_scantuple; ... EEOP_SCAN_FETCHSOME: slot_getsomeattrs(scanslot, op->d.fetch.last_var); So someattrs loaded into oldslot, which is released after         trigtuple = ExecFetchSlotHeapTuple(oldslot, true, &should_free_trig) But before 86dc90056 we had: ExecFilterJunk(junkfilter=relinfo->ri_junkFilter, slot=epqslot_candidate): -> slot_getallattrs(slot); -> slot_getsomeattrs(slot, slot->tts_tupleDescriptor->natts); I. e., someattrs were loaded into the epqslot_candidate slot, which wasn't touched by ExecFetchSlotHeapTuple(oldslot,...) and the newslot's contents survived the call. It's not a final conclusion, but maybe it could be helpful for someone who investigates it too. Best regards, Alexander