pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ronan Dunklau <ronan.dunklau@dalibo.com>
To: Heikki Linnakangas <hlinnakangas@vmware.com>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
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> (raw)
In-Reply-To: <528CA074.4030307@vmware.com>
References: <2450353.1U6Qoyzd8o@ronan_laptop>
	<528CA074.4030307@vmware.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Le mercredi 20 novembre 2013 13:43:48 Heikki Linnakangas a écrit :
> On 19.11.2013 16:24, Ronan Dunklau wrote:
> > Hello.
> > 
> > While building a query on the pg_index relation, I came accross a bug
> > which
> > simplest form is manifested as this:
> > 
> > select
> > 
> >   a.indkey[1:3],
> >   a.indkey[1:2]
> > 
> > from pg_index as a
> > 
> > This can result either in a segfault, a failed memory allocation or
> > gibberish results.
> 
> Hmm. int2vectorout expects the int2vector to have a single dimension,
> but array_get_slice() returns a zero-dimension array if the result is empty.
> 
> 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-based,
> 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 back,
> you'll get an error.
> 
> 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 that
> 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.
> 
> Thanks for the report!
> 
> - Heikki

Are the differences between int2vector and a regular array documented somewhere 
? What is the purpose of using this datatype instead of int2[] ? 

On a sidenote, I would probably never have stumbled upon this bug if it was 
clear that an int2vector was 0 indexed. 

-- 
Ronan Dunklau
http://dalibo.com - http://dalibo.org

Attachments:

  signature.asc (application/pgp-signature, 489B) download

view thread (5+ messages)  latest in thread

Message-ID: <4213215.ZNM1LcEDmZ@ronan_laptop>
Permalink:  ../4213215.ZNM1LcEDmZ@ronan_laptop/
Also on:    postgresql.org/message-id/4213215.ZNM1LcEDmZ@ronan_laptop

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: ronan.dunklau@dalibo.com, hlinnakangas@vmware.com
  Subject: Re: Server may segfault when using slices on int2vector
  In-Reply-To: <4213215.ZNM1LcEDmZ@ronan_laptop>
  References: <2450353.1U6Qoyzd8o@ronan_laptop> <528CA074.4030307@vmware.com> <4213215.ZNM1LcEDmZ@ronan_laptop>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox