Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h2Zcz-0000BI-44 for pgsql-bugs@arkaria.postgresql.org; Sat, 09 Mar 2019 10:54:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h2Zcx-0001rW-Ih for pgsql-bugs@arkaria.postgresql.org; Sat, 09 Mar 2019 10:54:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h2Zcx-0001kx-Aa for pgsql-bugs@lists.postgresql.org; Sat, 09 Mar 2019 10:54:51 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h2Zcq-00040S-0X for pgsql-bugs@lists.postgresql.org; Sat, 09 Mar 2019 10:54:50 +0000 Received: by mail-wr1-x429.google.com with SMTP id o7so34500wrp.12 for ; Sat, 09 Mar 2019 02:54:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=76yBXa7vaPOGHOFb5bRsVjNm/ZuMBfuL2izUitSv6VU=; b=IAl3VjdxWnUsYEqt8CWJa3D2ejqqRujc1Fcoehp/do/fAq2icMy6ZnPlcqHevLwmf2 rXbpB/QLyznAaZZM9VkPtYN5yFUil55fvCK3wm0pPyXCRzoZAvl0r/SV2OPk/y2eytWs 4G1H3E1lHQbUyYYnOlI6TzBGGi2q8MiSlIewYr4QjrACTuh7TqatAIxgW5uqyap6AsLa V7SmXjWVf0NKtBQSuEUdE5QWc1yhw/Bmkzi/KT80cttZxFAplEATkqp5FhAr94uJvBYG y3GGcflTHyTcixsZANj9z46NIu9ArZL8e/4OX/rejBwUjQ9J1L2KhPWo+6IyaOrJRGCJ c0NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=76yBXa7vaPOGHOFb5bRsVjNm/ZuMBfuL2izUitSv6VU=; b=fXcSJYq6FeAiQvD18qjd5NO/s3vI2ABZshCZcP1nB6xLSANpIX9zCkW5j0NhdSIGim K48irFY1jupfSzmWlmaSMPUZCZrAHvjN7la00l9CNTIKDi89FK/oDKC8L8cZ3XTht3xD HugX3H3nn+aJr+o21US/0gZbFZe6+8Nz74zWsECYLnGWx5AtEJ1VX4NNx85z/SN3M+9H HzWthEDmp9ABaz5QE9/j15WIkofOTAx7Ur/6FUAUrTzrsd5eSfeLgcsH2cTmz4l9+TKO pfy5f6xXgIoK0/ZZcc5N+kcxn9HwxIQSDNaUgMw6HPaNLWhgL0kWn9SWuVA77G4BhvEk FJnw== X-Gm-Message-State: APjAAAVwSDj2IYWOaAUzUHkqyCSdb6yS7H22AUZxLSUZjECZM/yB3iMI SWst11QiTLWCSEKq48hHuyLtOGbT X-Google-Smtp-Source: APXvYqwqV3nP7otaSDmCb20Bbw0c3anxfTYhFynVWLM0ecdS+dD2+Vss7b2KzCF7D4u8cMHgrVTVvw== X-Received: by 2002:adf:cd0b:: with SMTP id w11mr9267733wrm.95.1552128881953; Sat, 09 Mar 2019 02:54:41 -0800 (PST) Received: from [192.168.0.10] ([95.180.47.253]) by smtp.gmail.com with ESMTPSA id r63sm16385102wmr.32.2019.03.09.02.54.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Mar 2019 02:54:41 -0800 (PST) Subject: Re: BUG #15653: pg_detoast_datum_packed problem From: =?UTF-8?Q?gmail_Vladimir_Kokovi=c4=87?= To: Andrew Gierth Cc: pgsql-bugs@lists.postgresql.org References: <15653-a9979a97bd11577d@postgresql.org> <8a0d54a5-1c94-aa00-7e22-7d16566839b4@gmail.com> <13b4fc8a-b790-ddec-bf02-fe99ed793a5b@gmail.com> <87a7i5b2ok.fsf@news-spur.riddles.org.uk> <5236e747-2107-35f8-6741-99298f0bd6a4@gmail.com> <87r2bg9yb2.fsf@news-spur.riddles.org.uk> Message-ID: Date: Sat, 9 Mar 2019 11:54:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------4E3EF1923B8464E537DC2FFF" Content-Language: en-GB List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------4E3EF1923B8464E537DC2FFF Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi Andrew, I forgot to show the final version of pg_bvarchar. /* SQL function: bvarchar(varchar) returns bytea */ PG_FUNCTION_INFO_V1(pg_bvarchar); Datum pg_bvarchar(PG_FUNCTION_ARGS) {   VarChar *arg = PG_GETARG_VARCHAR_PP(0);   unsigned len;   bytea *res;   len = VARSIZE_ANY_EXHDR(arg);   res = (text *) palloc(len);   SET_VARSIZE(res, len + VARHDRSZ);   memcpy(VARDATA(res), VARDATA_ANY(arg), len);   PG_RETURN_BYTEA_P(res); } On 9.3.19. 11:08, gmail Vladimir Koković wrote: > Hi Andrew, > > You are absolutely right and "select ", OID from ispp_wmpl where > (bvarchar (key))> = (bvarchar ('W' :: varchar)) and (bvarchar (key)) > <= (bvarchar ~~~~~~~~ ':: varchar)) order by key" has passed! However, > pg log file now has hundreds of warning message: 2019-03-09 10:53:29 > CET ispp-pionir-test :: 1 (53858) 14721 0 01000 WARNING: problem in > allocation set ExprContext: detected write past chunk end block > 0x55ccb0b36468, chunk 0x55ccb0b36490 2019-03-09 10:53:29 CET > ispp-pionir-test :: 1 (53858) 14721 0 01000 WARNING: problem in > allocation set ExprContext: detected write past chunk end in block > 0x55ccb0b36468, chunk 0x55ccb0b36490 2019-03-09 10:53:29 CET > ispp-pionir-test :: 1 (53858) 14721 0 01000 WARNING: problem in > allocation set ExprContext: detected write past chunk end in block > 0x55ccb0b36468, chunk 0x55ccb0b36490 ... Andrew, I have to thank you > for this help because without this, my 'select' would never have passed. Vladimir Koković, DP senior(69) > Belgrade, Mar. 9 2019 > > On 9.3.19. 10:48, Andrew Gierth wrote: > "gmail" == gmail Vladimir Koković writes: >> gmail> Hi Andrew. >> gmail> I changed VARSIZE to VARSIZE_ANY_EXHDR and VARDATA in >> gmail> VARDATA_ANY as you said, but there is still a problem I can not >> gmail> understand ! >> >> Your message formatting was all messed up, but I can see that you are >> still subtracting VARHDRSZ - don't do that: VARSIZE_ANY_EXHDR already >> has the header size subtracted (hence "EXHDR"), it returns only the data >> size. (The header size is variable, 1 or 4 bytes, so it wouldn't make >> sense to include it.) >> --------------4E3EF1923B8464E537DC2FFF Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hi Andrew,

I forgot to show the final version of pg_bvarchar.

/* SQL function: bvarchar(varchar) returns bytea */

PG_FUNCTION_INFO_V1(pg_bvarchar);
Datum pg_bvarchar(PG_FUNCTION_ARGS) {
  VarChar *arg = PG_GETARG_VARCHAR_PP(0);
  unsigned len;
  bytea *res;

  len = VARSIZE_ANY_EXHDR(arg);
  res = (text *) palloc(len);
  SET_VARSIZE(res, len + VARHDRSZ);
  memcpy(VARDATA(res), VARDATA_ANY(arg), len);
  PG_RETURN_BYTEA_P(res);
}


On 9.3.19. 11:08, gmail Vladimir Koković wrote:

Hi Andrew,

You are absolutely right and "select ", OID from ispp_wmpl where (bvarchar (key))> = (bvarchar ('W' :: varchar)) and (bvarchar (key)) <= (bvarchar ~~~~~~~~ ':: varchar)) order by key" has passed!

However, pg log file now has hundreds of warning message:
2019-03-09 10:53:29 CET ispp-pionir-test :: 1 (53858) 14721 0 01000 WARNING: problem in allocation set ExprContext: detected write past chunk end block 0x55ccb0b36468, chunk 0x55ccb0b36490
2019-03-09 10:53:29 CET ispp-pionir-test :: 1 (53858) 14721 0 01000 WARNING: problem in allocation set ExprContext: detected write past chunk end in block 0x55ccb0b36468, chunk 0x55ccb0b36490
2019-03-09 10:53:29 CET ispp-pionir-test :: 1 (53858) 14721 0 01000 WARNING: problem in allocation set ExprContext: detected write past chunk end in block 0x55ccb0b36468, chunk 0x55ccb0b36490 
...
Andrew, I have to thank you for this help because without this, my 'select' would never have passed.


Vladimir Koković, DP senior(69)
Belgrade, Mar. 9 2019

On 9.3.19. 10:48, Andrew Gierth wrote:

"gmail" == gmail Vladimir Koković <vladimir.kokovic@gmail.com> writes:
 gmail> Hi Andrew.
 gmail> I changed VARSIZE to VARSIZE_ANY_EXHDR and VARDATA in
 gmail> VARDATA_ANY as you said, but there is still a problem I can not
 gmail> understand !

Your message formatting was all messed up, but I can see that you are
still subtracting VARHDRSZ - don't do that: VARSIZE_ANY_EXHDR already
has the header size subtracted (hence "EXHDR"), it returns only the data
size. (The header size is variable, 1 or 4 bytes, so it wouldn't make
sense to include it.)

--------------4E3EF1923B8464E537DC2FFF--