Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vj6QZ-0003wj-Dp for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Nov 2013 11:58:39 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vj6QY-0004G2-N7 for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Nov 2013 11:58:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vj6QX-0004Fv-Lm for pgsql-bugs@postgresql.org; Wed, 20 Nov 2013 11:58:37 +0000 Received: from mimolette.dalibo.net ([212.85.154.222]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vj6QU-0000Vu-JE for pgsql-bugs@postgresql.org; Wed, 20 Nov 2013 11:58:37 +0000 Received: from ronan_laptop.localnet (unknown [78.193.41.71]) by mimolette.dalibo.net (Postfix) with ESMTPSA id B4CB1682001D; Wed, 20 Nov 2013 12:57:28 +0100 (CET) From: Ronan Dunklau To: Heikki Linnakangas Cc: pgsql-bugs Subject: Re: Server may segfault when using slices on int2vector Date: Wed, 20 Nov 2013 12:57:23 +0100 Message-ID: <4213215.ZNM1LcEDmZ@ronan_laptop> User-Agent: KMail/4.11.3 (Linux/3.12.0-gentoo; KDE/4.11.3; x86_64; ; ) In-Reply-To: <528CA074.4030307@vmware.com> References: <2450353.1U6Qoyzd8o@ronan_laptop> <528CA074.4030307@vmware.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1604741.Q5jRnjpzft"; micalg="pgp-sha1"; protocol="application/pgp-signature" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --nextPart1604741.Q5jRnjpzft Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Le mercredi 20 novembre 2013 13:43:48 Heikki Linnakangas a =E9crit : > On 19.11.2013 16:24, Ronan Dunklau wrote: > > Hello. > >=20 > > While building a query on the pg_index relation, I came accross a b= ug > > which > > simplest form is manifested as this: > >=20 > > select > >=20 > > a.indkey[1:3], > > a.indkey[1:2] > >=20 > > from pg_index as a > >=20 > > This can result either in a segfault, a failed memory allocation or= > > gibberish results. >=20 > Hmm. int2vectorout expects the int2vector to have a single dimension,= > but array_get_slice() returns a zero-dimension array if the result is= empty. >=20 > I don't think it's safe to allow slicing int2vectors (nor oidvectors)= . > It seems all too likely that the result violates the limitations of > int2vector. In addition to that segfault, the array returned is 1-bas= ed, > not 0-based as we assume for int2vectors. One consequence of that is > that if you COPY the value out in binary format and try to read it ba= ck, > you'll get an error. >=20 > So I think we should just not allow slicing oidvectors, and throw an > error. You can cast from int2vector to int2[], and slice and dice tha= t > as much as you want, so it's not a big loss in functionality. Another= > solution would to provide a specialized slice-function for int2vector= > and oidvector, but it's probably not worth the effort. >=20 > Thanks for the report! >=20 > - Heikki Are the differences between int2vector and a regular array documented s= omewhere=20 ? What is the purpose of using this datatype instead of int2[] ?=20 On a sidenote, I would probably never have stumbled upon this bug if it= was=20 clear that an int2vector was 0 indexed.=20 --=20 Ronan Dunklau http://dalibo.com - http://dalibo.org --nextPart1604741.Q5jRnjpzft Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQEcBAABAgAGBQJSjKOoAAoJEHSCNJt9TqXndjcH+wUfZfdo3Dm18R+Dy8G1atCo 8YA4S5eoekXnUXypYfzBoeVuw/QHs0TFxC7ID+u2kJ8vWY4y8GWsnPl+wcwykycc or9lRtLK4GDWT7qFY/JVvdQ8/kKvnZUXOSv2BMPuXT4a1wOZixQGxzUSlHUWweN4 EiDTqf6N9Ky9dcuYSA9OM59gaEd1dBjuLbNL4i4I07x9PFjegPyjRWM/0C8Wz7Gp dArkiCxn8X0YA/fiseL/xCsXTv1YKi5FAa5SjzrOhv7S+EQo+aiMthEf2aQmnuEl sPIwBQNTwSDpR5J1c5THNLMq24IuGjLbsb5xaanTgacHDlGLeJSWkXyZprpnvqY= =Qpi1 -----END PGP SIGNATURE----- --nextPart1604741.Q5jRnjpzft--