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 1qAWTN-0005Vh-KP for pgsql-bugs@arkaria.postgresql.org; Sat, 17 Jun 2023 14:00:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qAWTM-0006a2-H3 for pgsql-bugs@arkaria.postgresql.org; Sat, 17 Jun 2023 14:00:12 +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 1qAWTM-0006Zt-6t for pgsql-bugs@lists.postgresql.org; Sat, 17 Jun 2023 14:00:12 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qAWTF-002iRi-9R for pgsql-bugs@lists.postgresql.org; Sat, 17 Jun 2023 14:00:10 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f6195d2b3fso2260990e87.1 for ; Sat, 17 Jun 2023 07:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687010403; x=1689602403; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=HG62ccqWDviAWY1SHCHUllmUrEoCGFkCIZClnh1sOG0=; b=B0nPYwHJ546bMopQ/iJoO8EXxHGLXEucUBSKa42sCuzU8IW9VYjF7cCzbxSVPrDgNH TaVobbxsdoYvYVnpkopWneiW4PdV/01XIQeC9HbBg22PPsn+xcqKEI4Z7CNtJAqi0kSw t1MWK88Q6xy3JCZyk6u5GnvCbzK4vT0riyIEvipxP94XLlsFFBhQcft0juXRFajTgxpH uZjJe+UD9bGFfA74Om0krTwpfhfvmI0X9EEqLgdS4hg7f9MdX5jRQwzJ/JSMLaBgor9R ZQ4qy5GMdIW/XLXQr2DfhDZfBtLXdWrzFBVesvpNao36iMWQN5FIhFCpr2UfYuwKUH52 ZAnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687010403; x=1689602403; h=in-reply-to:from:references: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=HG62ccqWDviAWY1SHCHUllmUrEoCGFkCIZClnh1sOG0=; b=HFLPMej9KR1SQV1Mq5Dl2DOJHhE7P/z3/oIlch48atjfgkUUIg/uxSvfbnnxgH6Vnp oxVDtgNkp2d0nebv0+2jUzEucQtiYDq2K5FX1hqY2qM9mpZv9T1e9/aGsfVyp3iv7uMa 5Ob5vrwCSJWqy5OWugaN/hfgM7BwqvD7sAUE+0JxzxaTShSAQU18sBKbYhxTERJ+zT6C PNGZsqZ+jNT0/cQJEBL75CBHX2C0KaA1Jx1JKCZAQl1+pbR0gj28MBW+JRgw1y7r4UsC ym5V4EKdOOOeTlQHMYr3ewkE4Y7U6O9mcxAmbutWkZzATnwyOS5Cil/MfQredY8iiXFa bJOA== X-Gm-Message-State: AC+VfDw5hOMUV72d7HRpoSjGv/ygXDrnw/6eElsi98aeh+YpQ+OmqnGc n5Nyg3gcUAvJC4Ccol3Br3us6lc00O8= X-Google-Smtp-Source: ACHHUZ4boKVK6eANxp1717UrrW1kzmoXb9CC/LTVrDIU3NzjOfZnueXtitTxRjPiUuTXv30UTHnCvw== X-Received: by 2002:a19:5017:0:b0:4f6:266c:22fa with SMTP id e23-20020a195017000000b004f6266c22famr3265594lfb.49.1687010403376; Sat, 17 Jun 2023 07:00:03 -0700 (PDT) Received: from [1.0.0.7] ([178.155.23.108]) by smtp.gmail.com with ESMTPSA id k12-20020ac2456c000000b004f37c22b410sm3468111lfm.67.2023.06.17.07.00.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Jun 2023 07:00:02 -0700 (PDT) Content-Type: multipart/mixed; boundary="------------iXUjEIJRWkB0pVINtqKBij3y" Message-ID: Date: Sat, 17 Jun 2023 17: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 #17950: Incorrect memory access in gtsvector_picksplit() Content-Language: en-US To: pgsql-bugs@lists.postgresql.org References: <17950-6c80a8d2b94ec695@postgresql.org> From: Alexander Lakhin In-Reply-To: <17950-6c80a8d2b94ec695@postgresql.org> 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. --------------iXUjEIJRWkB0pVINtqKBij3y Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 29.05.2023 23:00, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 17950 I managed to reduce the reproducer to the following: CREATE TABLE tst(t tsvector); INSERT INTO tst SELECT array_to_string(array(SELECT 'a' || x::text FROM generate_series(1, 125) x), ' ')::tsvector FROM generate_series(1, 3000); INSERT INTO tst SELECT '' FROM generate_series(1, 100); CREATE INDEX gistidx ON tst USING gist (t tsvector_ops(siglen=1)); (Sorry for the previous messy script.) A trivial fix for the issue is attached. BTW, when looking at the index contents (page 0) using pageinspect, I saw:  itemoffset |    ctid     | itemlen | dead | keys ------------+-------------+---------+------+-----------------------------------           1 | (367,65535) |      16 | f    | (a)=("0 true bits, 0 false bits")           2 | (368,65535) |      16 | f    | (a)=("0 true bits, 0 false bits") The text describing keys looks confusing, just as if siglen was 0, but it's not the case. This is explained by the code:         int            siglen = GETSIGLEN(key);         int            cnttrue = (ISALLTRUE(key)) ? SIGLENBIT(siglen) : sizebitvec(GETSIGN(key), siglen);         sprintf(outbuf, SINGOUTSTR, cnttrue, (int) SIGLENBIT(siglen) - cnttrue); When ISALLTRUE, the code tries to calculate bit count from siglen, but siglen is 0 in this case. So maybe fix it in passing too... Best regards, Alexander --------------iXUjEIJRWkB0pVINtqKBij3y Content-Type: text/x-patch; charset=UTF-8; name="v1-01-fix-gtsvector_picksplit.patch" Content-Disposition: attachment; filename="v1-01-fix-gtsvector_picksplit.patch" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL3V0aWxzL2FkdC90c2dpc3RpZHguYyBiL3NyYy9i YWNrZW5kL3V0aWxzL2FkdC90c2dpc3RpZHguYwppbmRleCBmMGNkMjg2NmZmLi4xMmE0MTEx ZTk5IDEwMDY0NAotLS0gYS9zcmMvYmFja2VuZC91dGlscy9hZHQvdHNnaXN0aWR4LmMKKysr IGIvc3JjL2JhY2tlbmQvdXRpbHMvYWR0L3RzZ2lzdGlkeC5jCkBAIC03MzAsNyArNzMwLDcg QEAgZ3RzdmVjdG9yX3BpY2tzcGxpdChQR19GVU5DVElPTl9BUkdTKQogCQkJCXNpemVfYWxw aGEgPSBTSUdMRU5CSVQoc2lnbGVuKSAtCiAJCQkJCXNpemViaXR2ZWMoKGNhY2hlW2pdLmFs bGlzdHJ1ZSkgPwogCQkJCQkJCSAgIEdFVFNJR04oZGF0dW1fbCkgOgotCQkJCQkJCSAgIEdF VFNJR04oY2FjaGVbal0uc2lnbiksCisJCQkJCQkJICAgY2FjaGVbal0uc2lnbiwKIAkJCQkJ CQkgICBzaWdsZW4pOwogCQl9CiAJCWVsc2UKQEAgLTc0NCw3ICs3NDQsNyBAQCBndHN2ZWN0 b3JfcGlja3NwbGl0KFBHX0ZVTkNUSU9OX0FSR1MpCiAJCQkJc2l6ZV9iZXRhID0gU0lHTEVO QklUKHNpZ2xlbikgLQogCQkJCQlzaXplYml0dmVjKChjYWNoZVtqXS5hbGxpc3RydWUpID8K IAkJCQkJCQkgICBHRVRTSUdOKGRhdHVtX3IpIDoKLQkJCQkJCQkgICBHRVRTSUdOKGNhY2hl W2pdLnNpZ24pLAorCQkJCQkJCSAgIGNhY2hlW2pdLnNpZ24sCiAJCQkJCQkJICAgc2lnbGVu KTsKIAkJfQogCQllbHNlCg== --------------iXUjEIJRWkB0pVINtqKBij3y Content-Type: text/x-patch; charset=UTF-8; name="v1-02-fix-gtsvectorout.patch" Content-Disposition: attachment; filename="v1-02-fix-gtsvectorout.patch" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL3V0aWxzL2FkdC90c2dpc3RpZHguYyBiL3NyYy9i YWNrZW5kL3V0aWxzL2FkdC90c2dpc3RpZHguYwppbmRleCAxMmE0MTExZTk5Li4yNzIyYzAy NDU3IDEwMDY0NAotLS0gYS9zcmMvYmFja2VuZC91dGlscy9hZHQvdHNnaXN0aWR4LmMKKysr IGIvc3JjL2JhY2tlbmQvdXRpbHMvYWR0L3RzZ2lzdGlkeC5jCkBAIC0xMTUsMTAgKzExNSwx NSBAQCBndHN2ZWN0b3JvdXQoUEdfRlVOQ1RJT05fQVJHUykKIAkJc3ByaW50ZihvdXRidWYs IEFSUk9VVFNUUiwgKGludCkgQVJSTkVMRU0oa2V5KSk7CiAJZWxzZQogCXsKLQkJaW50CQkJ c2lnbGVuID0gR0VUU0lHTEVOKGtleSk7Ci0JCWludAkJCWNudHRydWUgPSAoSVNBTExUUlVF KGtleSkpID8gU0lHTEVOQklUKHNpZ2xlbikgOiBzaXplYml0dmVjKEdFVFNJR04oa2V5KSwg c2lnbGVuKTsKKwkJaWYgKElTQUxMVFJVRShrZXkpKQorCQkJc3ByaW50ZihvdXRidWYsICJh bGwgdHJ1ZSBiaXRzIik7CisJCWVsc2UKKwkJeworCQkJaW50CQkJc2lnbGVuID0gR0VUU0lH TEVOKGtleSk7CisJCQlpbnQJCQljbnR0cnVlID0gKElTQUxMVFJVRShrZXkpKSA/IFNJR0xF TkJJVChzaWdsZW4pIDogc2l6ZWJpdHZlYyhHRVRTSUdOKGtleSksIHNpZ2xlbik7CiAKLQkJ c3ByaW50ZihvdXRidWYsIFNJTkdPVVRTVFIsIGNudHRydWUsIChpbnQpIFNJR0xFTkJJVChz aWdsZW4pIC0gY250dHJ1ZSk7CisJCQlzcHJpbnRmKG91dGJ1ZiwgU0lOR09VVFNUUiwgY250 dHJ1ZSwgKGludCkgU0lHTEVOQklUKHNpZ2xlbikgLSBjbnR0cnVlKTsKKwkJfQogCX0KIAog CVBHX0ZSRUVfSUZfQ09QWShrZXksIDApOwo= --------------iXUjEIJRWkB0pVINtqKBij3y--