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 1ppR5F-0001Hh-C3 for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Apr 2023 10:00:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ppR5E-0003dJ-5Q for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Apr 2023 10:00:08 +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 1ppR5D-0003dA-My for pgsql-bugs@lists.postgresql.org; Thu, 20 Apr 2023 10:00:07 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1ppR5B-000rAZ-Hl for pgsql-bugs@lists.postgresql.org; Thu, 20 Apr 2023 10:00:06 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4eed764a10cso455633e87.0 for ; Thu, 20 Apr 2023 03:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681984804; x=1684576804; h=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=pEAQiU5cWdnGoDDPr+CpZEYGI1eRIFlGj7tZr5J4cI0=; b=T0VxDiUbwCUJppx60/rxKXsw56cE5bG1xQoAQi9ew+gqLf+FEyOsUb/MkRNFxEr71f fo62lNvmeIOcafiPV6uDyL06oLA4t/C+5HQRyjCQW5Eggv7Jo7Sf54nQx0rbXEAO98L0 Vegx6czx5loLdkrUXib10NkQVvBl2XgvOArtA3bCPUmSxoDlzwR4QX6EmXWYRZK4CmMr 3K1n5p6s9/kCzJUFOp5cNOlvG7e9bHmLeezUYoOP3IJ7dRwAcIOnEX2hcc0RDktTbqsn qy3t7L7RcSBnmymhXy9bl8VbRWkZZXHkFvLq5Hj1CgEyrltAmNULoG7kFZy1mL7m98Mi E+zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681984804; x=1684576804; h=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=pEAQiU5cWdnGoDDPr+CpZEYGI1eRIFlGj7tZr5J4cI0=; b=X2dZZKHoawDuxl+qifJiTNN8yHLRp0tFt9sH4/mQIlNT9OuFH5T82uJ6RAplpMhp/0 no31U1QIf/rMyH9Iwgd9InFWsAA66D2tFdF5Ml574ojEdgLoVHzPq7KwVcH5+1Jl3DB5 6JtIvP5N62Nqu38IWsF4dV1fXdylGQfpOyu+0O9sXCYIP5PuUwSoZMPV6IyFYUskRxK5 g+2UfGR585yvPs/yBxrm3SidenxVW34pMreycOpXbS9dxtCfjfqqA8VOgBIu/Plt06zY CzKpKrP5i4a1lQffB02IHsyRpaBLkIU3hPCbpUuAee11PNCijlUXP1hmvJyxaP61jzAW zUjQ== X-Gm-Message-State: AAQBX9d5LddB+QN9sOQFvJOTTv3KETeSXFQC9y+g+RBRDw8uHy4122Mq dyLYGysEoyDpWpywLIgaTbI= X-Google-Smtp-Source: AKy350Y+G0NR5EcqkDvliT4xlwdHt88yExplXQQjmjaiOMKWWJUf0HHW0JKFqjF/cv5JtxqRYAJfBQ== X-Received: by 2002:ac2:5699:0:b0:4ed:ca97:2feb with SMTP id 25-20020ac25699000000b004edca972febmr289130lfr.61.1681984803806; Thu, 20 Apr 2023 03:00:03 -0700 (PDT) Received: from [1.0.0.7] ([178.155.21.87]) by smtp.gmail.com with ESMTPSA id o15-20020ac2494f000000b004db266f3978sm165214lfi.174.2023.04.20.03.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Apr 2023 03:00:02 -0700 (PDT) Content-Type: multipart/mixed; boundary="------------D6IFwAhHL6YBCxxNAjxNmdOJ" Message-ID: Date: Thu, 20 Apr 2023 13: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: Richard Guo Cc: pgsql-bugs@lists.postgresql.org References: <17798-0907404928dcf0dd@postgresql.org> <87fe6c28-80b2-f709-a8db-d105e5240e39@gmail.com> From: Alexander Lakhin In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------D6IFwAhHL6YBCxxNAjxNmdOJ Content-Type: multipart/alternative; boundary="------------lcTzTIO0oUGhx8eHuz9Y0A0Z" --------------lcTzTIO0oUGhx8eHuz9Y0A0Z Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello Richard, 19.04.2023 11:29, Richard Guo wrote: > I have a second look at this issue and now I think the fix in v1 patch > is correct.  I think the comment needs to be updated for this change, > maybe something like > >   * (Typically, newslot was also generated by ExecGetUpdateNewTuple, so >   * that epqslot_clean will be that same slot and the copy step below > - * is not needed.) > + * is not needed.  And we need to materialize newslot in this case, > + * since its tuple might be dependent on oldslot's storage, which > + * might not be a local copy and be freed before we fetch newslot's > + * tuple.) Thanks for looking into this! I've updated the comment based on your suggestion. Please look at the patch attached. I hesitate to add the isolation test to the patch as adding a dedicated test just for this case seems too wasteful to me. Maybe that scenario could be added to one of the existing trigger-related tests, but I couldn't find a test, which is generic enough for that. Best regards, Alexander --------------lcTzTIO0oUGhx8eHuz9Y0A0Z Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Hello Richard,

19.04.2023 11:29, Richard Guo wrote:
I have a second look at this issue and now I think the fix in v1 patch
is correct.  I think the comment needs to be updated for this change,
maybe something like

  * (Typically, newslot was also generated by ExecGetUpdateNewTuple, so
  * that epqslot_clean will be that same slot and the copy step below
- * is not needed.)
+ * is not needed.  And we need to materialize newslot in this case,
+ * since its tuple might be dependent on oldslot's storage, which
+ * might not be a local copy and be freed before we fetch newslot's
+ * tuple.)

Thanks for looking into this!

I've updated the comment based on your suggestion. Please look at the patch
attached.

I hesitate to add the isolation test to the patch as adding a dedicated
test just for this case seems too wasteful to me. Maybe that scenario could
be added to one of the existing trigger-related tests, but I couldn't find a
test, which is generic enough for that.

Best regards,
Alexander
--------------lcTzTIO0oUGhx8eHuz9Y0A0Z-- --------------D6IFwAhHL6YBCxxNAjxNmdOJ Content-Type: text/x-patch; charset=UTF-8; name="v2-01-Fix-memory-access-in-BRU-trigger.patch" Content-Disposition: attachment; filename="v2-01-Fix-memory-access-in-BRU-trigger.patch" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL2NvbW1hbmRzL3RyaWdnZXIuYyBiL3NyYy9iYWNr ZW5kL2NvbW1hbmRzL3RyaWdnZXIuYwppbmRleCA0YjI5NWY4ZGE1Li44MDI3NDk4YjczIDEw MDY0NAotLS0gYS9zcmMvYmFja2VuZC9jb21tYW5kcy90cmlnZ2VyLmMKKysrIGIvc3JjL2Jh Y2tlbmQvY29tbWFuZHMvdHJpZ2dlci5jCkBAIC0yOTgxLDcgKzI5ODEsOSBAQCBFeGVjQlJV cGRhdGVUcmlnZ2VycyhFU3RhdGUgKmVzdGF0ZSwgRVBRU3RhdGUgKmVwcXN0YXRlLAogCQkg KgogCQkgKiAoVHlwaWNhbGx5LCBuZXdzbG90IHdhcyBhbHNvIGdlbmVyYXRlZCBieSBFeGVj R2V0VXBkYXRlTmV3VHVwbGUsIHNvCiAJCSAqIHRoYXQgZXBxc2xvdF9jbGVhbiB3aWxsIGJl IH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