Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVKOe-0006My-PR for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Jul 2017 16:21:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dVKOd-0000Kc-Rk for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Jul 2017 16:21:51 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dVKNs-0007Ra-VI for pgsql-bugs@postgresql.org; Wed, 12 Jul 2017 16:21:05 +0000 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dVKNl-0001O7-JL for pgsql-bugs@postgresql.org; Wed, 12 Jul 2017 16:21:03 +0000 Received: by mail-lf0-x243.google.com with SMTP id t72so3570885lff.0 for ; Wed, 12 Jul 2017 09:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=n1qy/TlGzMaGZXYauRzMV9DsY4M/PjcSUBizl0Vf6io=; b=S66D26tkdE6d4Dj0n5DZc197EggOoVH7dveyzST6VmfPGubtedTLtxlyYpfXZy6wOE YDlkOr4yewQt4EhpgSJDHFoC5edvONaV75CeqMcvsjRoj6A+AfJ0GyNi6BdII+gmMYfZ PEZUIXAVCRBoKrGdV3++6Hod7c3Qv7Zwl6xGREdJk72oWjnF1LbwFjeNrHXWbVPd3tcS +iwnKTODxL+8do7dHnLGNpxDzHxbUD5OZ3rHO9uky9bkLEel1Ydw2+ryVgDLfLEgFlUU RXnrjb6rVa8pWc6c9jJEI05TyxM3lFtPe2gjrEzlioxpGlVwM1E220avxgKxh4PE9sg6 S5FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:cc:from:message-id :date:user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=n1qy/TlGzMaGZXYauRzMV9DsY4M/PjcSUBizl0Vf6io=; b=KnpBR6kLz/VHEz0BEXxO22CX0Ht6CFSk5GqPks4iOIINgl6ZpLWTFBfh2DxDfs/9Ui ttGw1Hu/SX3mVtDleVhv317ACPDBnDJo72UErxZmkcx5Z4dQ3GLLfyjPE4oHZY+llLeS ITIxxQR20pdBvxRF/LLySDwOBJ7TEHj+jnOpMCz2qVaJ/sbfkUli6G59orZoRPFLm4KD cILNfmBZf4t7PXC/0QtoR0xeqfpJm90sOKRyoyjwNZ25zUFTe6dWg2W63ULapzUZ9NSO Et9X82p/2DhJiYOXsATsaiY3KMAJa9Cwpzs0KT8o9XRuwvZ5mmAw57dBMxLi6Qi25//5 marg== X-Gm-Message-State: AIVw112t+GyKLOc8lAaMwiyXOtZK11DOGpOwOy6MKEewRzsA6OIs0ykh cC4rL1UaEJnZ8IjM X-Received: by 10.46.71.139 with SMTP id u133mr2141702lja.45.1499876455225; Wed, 12 Jul 2017 09:20:55 -0700 (PDT) Received: from [192.168.1.99] (dsl-hkibng32-54fb4e-103.dhcp.inet.fi. [84.251.78.103]) by smtp.gmail.com with ESMTPSA id x144sm634994lff.56.2017.07.12.09.20.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jul 2017 09:20:54 -0700 (PDT) Subject: Re: BUG #14722: Segfault in tuplesort_heap_siftup, 32 bit overflow To: Tom Lane , Peter Geoghegan References: <20170629161637.1478.93109@wrigleys.postgresql.org> <1499281579.8258.32.camel@cmu.edu> <28906.1499292236@sss.pgh.pa.us> <20170705221414.bgnw73z2mwkjwor7@alap3.anarazel.de> <3de75af4-a49f-36d1-347f-f170693ce6f5@iki.fi> <4817.1499874124@sss.pgh.pa.us> <8081.1499876094@sss.pgh.pa.us> Cc: Andres Freund , Sergey Koposov , "pgsql-bugs@postgresql.org" From: Heikki Linnakangas Message-ID: <007e3020-3d27-8ac8-7269-9db7ebe9a8bf@iki.fi> Date: Wed, 12 Jul 2017 19:20:53 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <8081.1499876094@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit 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 07/12/2017 07:14 PM, Tom Lane wrote: > Peter Geoghegan writes: >> On Wed, Jul 12, 2017 at 8:42 AM, Tom Lane wrote: >>>> Another option to use "unsigned int", on the assumption that UINT_MAX >= >>>> INT_MAX * 2 + 1. > >>> Ah, that seems like a fine idea. > >> Works for me. > > I'll go make it so, unless Heikki's already on it? I'm not. Thanks! >> And to eliminate that assumption, we can use (UINT_MAX >> - 1) / 2 as the maximum size of the memtuples array, rather than INT_MAX. > > Uh ... what assumption? That's certainly true on any twos-complement > machine. Besides, if you're worried about hypothetical portability > issues, ... Right, it's a hypothetical portability issue. The assumption we're making is that UINT_MAX >= INT_MAX * 2 + 1. I'm not aware of any system where it's not true, but I don't know what the C standards say about that. > ... I'm not sure it's any better to assume that (UINT_MAX - 1) / 2 > fits in a signed int. Well, you could do Min(INT_MAX, (UINT_MAX - 1 / 2). Or just add a StaticAssertion for it. Or just note in a comment that we're making that assumption. - Heikki -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs