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 1kwVTv-0006zp-A7 for pgsql-bugs@arkaria.postgresql.org; Mon, 04 Jan 2021 19:25:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kwVTt-0004e2-V7 for pgsql-bugs@arkaria.postgresql.org; Mon, 04 Jan 2021 19:25:29 +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 1kwVTt-0004du-IK for pgsql-bugs@lists.postgresql.org; Mon, 04 Jan 2021 19:25:29 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kwVTm-0007G0-Ay for pgsql-bugs@lists.postgresql.org; Mon, 04 Jan 2021 19:25:28 +0000 Received: by mail-pg1-x530.google.com with SMTP id 15so19696491pgx.7 for ; Mon, 04 Jan 2021 11:25:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=legitimatesounding-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=7qOqCi4BqOTgaNy1LTd/c2uCs0Zp6nnWJPcASVoIg2I=; b=kasVgJJVegW5XHOjkhdjZRDeG+Zhn0EZHU5KKg7m2GZJx/AFgozU7DWhK3540YibYj rmy0GPPDDR3bXKbZK3dks4op6IDhQZ+XCmQoJM1o/rfSbWtW/WZPHV4M1DQS08wtez52 7s/TgbAS4tTT3wfB1snWIIb4xUqMrrgeNOSc6nf33UwIoOqE8DN2JBOYBGFBt17cStf/ QzAV0HR+rdXKaUFpEM3U2LVjbXtSMpcdflb3AqE1L/f21z+S2tjW11wdj1Yw4iRgs521 CcafLNdPksKPb8gB+xpBBaNeOI6wWN5zaxdhSaLczmxgiXQ6vrF3xmOgp0zX77PkTNlX gxPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=7qOqCi4BqOTgaNy1LTd/c2uCs0Zp6nnWJPcASVoIg2I=; b=lFRijQIPKS7qswivzG+GKfNzyW8QmnFPSyVNXHjKxjioyiCcYE0Vhvk48V/J7oioSz IeEBneqK9f1Jqdj7gZw39ev67xrqhZY303WFG2u131De8xtWHBPBG/sBmkZi/FwwIxKq AOqTdBkIbHENRVqLI8fbY1/H/jugtIeswbGFJbxwydW7SItbYfVx6Ts4UwWfKZsgvBPA Cy2pno4lBHdKFdU5yEyFcBnVDzmI0B7535fN3L+DQ5K5oVyiml7VDqLAfr7efPa0LJOp sbhTNOddQv5+NS9oFxdYMLVL9BW6LjNlTwi32eRCX+ZisyvILhGX8n1AeVSsQzq4Dzcp fPbQ== X-Gm-Message-State: AOAM532juW4f8dZGyQ1puAzGhU7NOW1/tOxBnJ9YgAUxFzri6ixsO9nu Hcdh018vuApGxXK7NRYtBH+9cA== X-Google-Smtp-Source: ABdhPJypwpWPfV4fpz/Ce5mcg/Aqz+a49cFw96Ispa+w57r5LNca7QUr5XojBfn6SQBqAjR8R6cZbA== X-Received: by 2002:a65:6a0c:: with SMTP id m12mr52325549pgu.27.1609788320075; Mon, 04 Jan 2021 11:25:20 -0800 (PST) Received: from [10.0.1.64] ([50.45.185.250]) by smtp.gmail.com with ESMTPSA id p15sm59066998pgl.19.2021.01.04.11.25.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jan 2021 11:25:18 -0800 (PST) From: Jerry Sievert Message-Id: <018A6952-DDF4-4728-AA47-A819CC6DB2CB@legitimatesounding.com> Content-Type: multipart/signed; boundary="Apple-Mail=_5B33F05F-E409-4CEA-A283-3657E8003DDA"; protocol="application/pgp-signature"; micalg=pgp-sha512 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.17\)) Subject: Re: BUG #16804: substring() function returns "negative substring length" error when using a large length argument Date: Mon, 4 Jan 2021 11:25:16 -0800 In-Reply-To: Cc: rafiss@gmail.com, PostgreSQL mailing lists To: Pavel Stehule References: <16804-f4eeeb6c11ba71d4@postgresql.org> X-Mailer: Apple Mail (2.3445.104.17) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_5B33F05F-E409-4CEA-A283-3657E8003DDA Content-Type: multipart/alternative; boundary="Apple-Mail=_CC7F41F4-344D-4341-A56C-5AE108A7FC56" --Apple-Mail=_CC7F41F4-344D-4341-A56C-5AE108A7FC56 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi, > On Jan 4, 2021, at 11:21 AM, Pavel Stehule = wrote: >=20 >=20 >=20 > po 4. 1. 2021 v 19:44 odes=C3=ADlatel PG Bug reporting form = > napsal: > > select substring('string' from 2 for 2147483646); >=20 > Actual result: >=20 > 2021-01-04 12:43:13.145 EST [85734] ERROR: negative substring length = not > allowed > 2021-01-04 12:43:13.145 EST [85734] STATEMENT:s > negative substring length not allowed >=20 > Minimally this is a bug and it should raise an error "integer out of = range". Probably in this case we can use MAX_INT as a special value of = unlimited length, although it is a little bit scary, because length is = an optional value. The attached patch should fix this issue. I do not = have access to Oracle to check the behaviour of this case there. Except according to the pg docs, it=E2=80=99s not out of range, it=E2=80=99= s one less than MAX_INT. The manual calls for it to be an integer, which is defined as: integer 4 bytes typical choice for integer -2147483648 to = +2147483647 The original bug report is one less than +2147483647, and thus should be = a valid value, no? --Apple-Mail=_CC7F41F4-344D-4341-A56C-5AE108A7FC56 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hi,

On Jan 4, 2021, at 11:21 AM, Pavel Stehule = <pavel.stehule@gmail.com> wrote:



po 4. 1. = 2021 v 19:44 odes=C3=ADlatel PG Bug reporting form <noreply@postgresql.org> napsal:
> select = substring('string' from 2 for 2147483646);

Actual result:

2021-01-04 = 12:43:13.145 EST [85734] ERROR:  negative substring length not
allowed
2021-01-04 12:43:13.145 EST [85734] = STATEMENT:s
negative substring length not allowed

Minimally this is = a bug and it should raise an error "integer out of range". Probably in = this case we can use MAX_INT as a special value of unlimited length, = although it is a little bit scary, because length is an optional value. = The attached patch should fix this issue. I do not have access to Oracle = to check the behaviour of this case = there.

Except according to the pg docs, it=E2=80=99s not = out of range, it=E2=80=99s one less than MAX_INT.

The manual calls for it to be an integer, which is = defined as:

integer4 bytestypical choice for integer-2147483648 to = +2147483647

The original bug report is one less = than +2147483647, and thus should be a valid value, no?


= --Apple-Mail=_CC7F41F4-344D-4341-A56C-5AE108A7FC56-- --Apple-Mail=_5B33F05F-E409-4CEA-A283-3657E8003DDA Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEv9XT3oInQCSATEnKNxuIn5UPutkFAl/za5wACgkQNxuIn5UP utnoZg/+MO2vToFFuMgznD3NS0AzDBHW02LKARc7NSJI5rbuaYTpnm2SuyXuQYHK q00ucGAvZJurg2Gf6A2Z1mmddCPlCAsyvU5L4sdi5aO6nsg/Ja0VANtRRlxezYmz XZc2gKEdFyoA4vvykStFYTDCiswsCtJWTPEuCoyfWMW0M3Lgpaa3+kGtLmh/V9Am uuOBDTBMGfYOLmQexwFDB9yeWl/hMKS29T0IEoCy0KP8hqVOqUNHrpOnJTh+DTtX mQmcINR6UeiEj6dLpHlr3r04ELgFHS8yUm6ICQAwYPSrPD9JsI2tB9oGaepLVGrB LxXn56G0L6ORRH3SfY/VkUav1z+4G9ELJvhZ7heTOG03aWRwYzYPc95qDJA+EL2a P0+TDlnd7Z1hLIa8wDjfVlczQb2bItsWQji3n8YQZvhjoTL2w2jRfoPz9wh0nA51 XzNcHzXaz2FpBiVV0UrmBWmPdd9yVm7g+9ZfVLNfX3s2GzwyNEj1JtaoI5bMaPmm i9ZsgDT4Qq+cuHeQTXgLeU+KLwFHr8L8jb8+0zScjrpmI9rQHjrBhpidytCeZ2T8 I2N0z/1HBvigXF+w1KnYfj+z+EGLI2Fy0WKT4M9m67MDLZTaT52TdFNSg85E8d1B VnhzsMHinGP72i9JHUJwYam/4iCJC2j2J3xaU75Vi6COl3T9KtA= =oJ0a -----END PGP SIGNATURE----- --Apple-Mail=_5B33F05F-E409-4CEA-A283-3657E8003DDA--