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 1nKfrt-0004EQ-BC for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Feb 2022 12:26:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nKfrr-0004gF-Fb for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Feb 2022 12:26:39 +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 1nKfrq-0004g2-Qu for pgsql-bugs@lists.postgresql.org; Thu, 17 Feb 2022 12:26:39 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nKfrm-0002Xd-HD for pgsql-bugs@lists.postgresql.org; Thu, 17 Feb 2022 12:26:38 +0000 Received: by mail-wm1-x32c.google.com with SMTP id y6-20020a7bc186000000b0037bdc5a531eso4465724wmi.0 for ; Thu, 17 Feb 2022 04:26:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=1p+4hgTje/sm0iwM5Fupn6CYWWOKM5RlNA2U+3pubQ4=; b=YrhfBspEPVKWLCDFYjocsTF8JqmrqNRnABMpxnpGzxYwWe32Tvf5PynRph1DDAH5n4 HKgxsokQNoAY5EuHRjoovgczk+CqJgOASsmI9gKu94sUzcEJx6iqs+F+1bpxHrIk5rUk PKXoidy0v/paGuLYRP+FN5uLsygnJ+dZHep4yxhbJqenCOidCt2n9TQkxTmU+YvjWvUs s8MHxULNLftcEykBXvd1TKt2Q0TBCtt50Du2FcVhZanKLPk/amTKtVxVEQq2EBL3V7aG rjnAu40FAVVBVqa+Rt8jPfa7M45vo9JZWtv1prVGHDV7UEwSRGE+1A+UIRmivOtuSBBf jtNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=1p+4hgTje/sm0iwM5Fupn6CYWWOKM5RlNA2U+3pubQ4=; b=FPMCz7aPPM/TIh167n9j2D8FuBdewz8XGXNTURY1v9Ub/QFCmbScr488k1IzWez29C skBcqsD1Ky0YwdoHcMOcNyMnLVe20APgq/wg515NcVnTdAqVNuxS6QbdiRFtLkTQ05/a +X9TmFVA1MCGr3MqyFK4a/YUB/pR1c3AYVRsvvkPYKBm2+CnAc0w0sB5PtHeBQ7M6jqj JQdGYRKs5cqkm+aQ98zgEl6JPoEA/4lb+mK3CQCT7AlNL+Y2Gg0HkqrfztxX/8Id24t7 K7prkZxmvuyyKee8dDFTVPzJTuBlQmZbm9D3D70bn6qH4dP2ebEQg5jldncpthiXw5ZN tPVA== X-Gm-Message-State: AOAM533HXe+tIYBosC6zygY6nCPMd9q+/ez1DQil0LeMSAtFZRWj0/Tw LGNg/Vrdum2JbuA+fUAbZJ8hiBl7EXKqRygVY23Yzz3JPt85il83CxDTlcV1A253KRcsUSY0eHE t0Jc5wZpL6EiXWLHx0wo41TY1/ed5AAuvto9Pw8BOTjF6sR7w27qZywf32zLzoCSMPH0LWTox40 bDpwptBevqgGhNwUkbGaZ1KWZ0jrq1r3YePgKEX4/3T0iS X-Google-Smtp-Source: ABdhPJyU9AcjdcEqZ2UinR5bmTVh8qB3TCk/llhtpiuNiuapaSGaUQx0qJ92/yO/D/kwjhGuEM+3Wg== X-Received: by 2002:a05:600c:29c6:b0:37b:ea53:4bb6 with SMTP id s6-20020a05600c29c600b0037bea534bb6mr6000309wmd.24.1645100792624; Thu, 17 Feb 2022 04:26:32 -0800 (PST) Received: from [10.137.0.18] (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id p7sm13940012wrr.95.2022.02.17.04.26.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Feb 2022 04:26:31 -0800 (PST) Message-ID: Date: Thu, 17 Feb 2022 13:26:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: BUG #17406: Segmentation fault on GiST index after 14.2 upgrade Content-Language: en-US To: Peter Geoghegan Cc: Victor Yegorov , PostgreSQL mailing lists References: <17406-71e02820ae79bb40@postgresql.org> <788a0a51-b1e3-3601-5783-3f6488796ec4@enterprisedb.com> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/17/22 03:52, Peter Geoghegan wrote: > On Wed, Feb 16, 2022 at 4:16 PM Tomas Vondra > wrote: >> test=# SELECT * FROM gist_page_items(get_raw_page('path_gist_idx', 0), >> 'path_gist_idx'); > > Maybe this is obvious, but just in case: gist_page_items is *very* > trusting here. It's necessary to use gist_page_items_bytea() if you're > not 100% sure about the index definition for the index page you > provide. The fact that you can display the contents of each tuple > using the underlying type's own output function is very handy. But > potentially hazardous. > Sure, but I used this to inspect the index from example in our docs: https://www.postgresql.org/docs/14/ltree.html#id-1.11.7.30.8 I doubt we can be even more sure about the index definition. I don't know what the root cause is yet, but the memory corruption happens simply because ltree_out() sees entirely bogus data when executed from gist_page_items. For example it gets 16B varlena, allocates 16B string for it, and starts iterating over the ltree data. The it finds the first element is 60B long and happily copies it "into" the 16B buffer. That can't end well, obviously. Clearly, the ltree values are mangled somehow / somewhere. The funny thing is the bytea always looks 8B longer and with bogus data. So for example if you select this ltree from the table directly Top.Collections.Pictures.Astronomy.Astronauts then ltree_out sees it as 80B varlena, with 5 levels. But if ltree_out gets called from gist_page_items, then it sees 88B with 1 level, which is completely bogus. And funnily enough, if you do this at the beginning of ltree_out: in = (ltree *) ((char *) in + 8); then gist_page_items() starts working just fine. So, I guess gist_page_items() is broken/confused in some way. I'm not sure if this is related to the crash reported by Victor or a separate, independent issue. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company