Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dl1Iq-0001Lv-6I for pgsql-general@arkaria.postgresql.org; Thu, 24 Aug 2017 23:12:44 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dl1Ip-0002D2-NZ for pgsql-general@arkaria.postgresql.org; Thu, 24 Aug 2017 23:12:43 +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 1dl1GP-0006LR-J2 for pgsql-general@postgresql.org; Thu, 24 Aug 2017 23:10:13 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dl1GI-0000sw-W7 for pgsql-general@postgresql.org; Thu, 24 Aug 2017 23:10:12 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v7ONA4st017248; Thu, 24 Aug 2017 19:10:04 -0400 From: Tom Lane To: Michael Paquier cc: Igor Korot , pgsql-general Subject: Re: Retrieving query results In-reply-to: References: <32584.1503579096@sss.pgh.pa.us> <14978.1503586593@sss.pgh.pa.us> Comments: In-reply-to Michael Paquier message dated "Fri, 25 Aug 2017 07:57:50 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17246.1503616204.1@sss.pgh.pa.us> Date: Thu, 24 Aug 2017 19:10:04 -0400 Message-ID: <17247.1503616204@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org Michael Paquier writes: > On Thu, Aug 24, 2017 at 11:56 PM, Tom Lane wrote: >> I haven't tried it, but it sure looks like it would, if you don't hit >> OOM first. pqAddTuple() isn't doing anything to guard against integer >> overflow. The lack of reports implies that no one has ever tried to >> retrieve even 1G rows, let alone more ... > Yeah, looking at the code we would just need to check if ntups gets > negative (well, equal to INT_MIN) after being incremented. I think the real problem occurs where we realloc the array bigger. tupArrSize needs to be kept to no more than INT_MAX --- and, ideally, it should reach that value rather than dying on the iteration after it reaches 2^30 (so that we support resultsets as large as we possibly can). Without a range-check, it's not very clear what realloc will think it's being asked for. Also, on 32-bit machines, we could overflow size_t before tupArrSize even gets that big, so a test against SIZE_MAX/sizeof(pointer) may be needed as well. As long as we constrain tupArrSize to be within bounds, we don't have to worry about overflow of ntups per se. regards, tom lane -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general