Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vj6CN-0003ME-B3 for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Nov 2013 11:43:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vj6CM-000287-Ly for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Nov 2013 11:43:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vj6CL-000280-O0 for pgsql-bugs@postgresql.org; Wed, 20 Nov 2013 11:43:57 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vj6CI-0000Cw-Kc for pgsql-bugs@postgresql.org; Wed, 20 Nov 2013 11:43:57 +0000 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 7809E28A66; Wed, 20 Nov 2013 03:43:50 -0800 (PST) Received: from zcs-prod-ext-mta-1.vmware.com (zcs-prod-ext-mta-1.vmware.com [10.113.62.223]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id 738D5183C4; Wed, 20 Nov 2013 03:43:50 -0800 (PST) Received: from zcs-prod-ext-mta-1.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTP id C8F75120031; Wed, 20 Nov 2013 03:43:54 -0800 (PST) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTPSA; Wed, 20 Nov 2013 03:43:53 -0800 (PST) Message-ID: <528CA074.4030307@vmware.com> Date: Wed, 20 Nov 2013 13:43:48 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131005 Icedove/17.0.9 MIME-Version: 1.0 To: Ronan Dunklau CC: pgsql-bugs Subject: Re: Server may segfault when using slices on int2vector References: <2450353.1U6Qoyzd8o@ronan_laptop> In-Reply-To: <2450353.1U6Qoyzd8o@ronan_laptop> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -7.4 (-------) 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 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 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs