Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Thm8Z-0007ZM-QO for pgsql-bugs@arkaria.postgresql.org; Sun, 09 Dec 2012 19:02:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Thm8Y-0004yQ-7g for pgsql-bugs@arkaria.postgresql.org; Sun, 09 Dec 2012 19:02:02 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Thm8W-0004yH-8m for pgsql-bugs@postgresql.org; Sun, 09 Dec 2012 19:02:00 +0000 Received: from mail-pb0-f46.google.com ([209.85.160.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Thm8T-0005ae-E3 for pgsql-bugs@postgresql.org; Sun, 09 Dec 2012 19:01:58 +0000 Received: by mail-pb0-f46.google.com with SMTP id wy7so1399455pbc.19 for ; Sun, 09 Dec 2012 11:01:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:subject:from:to:date:content-type:x-mailer :content-transfer-encoding:mime-version:x-gm-message-state; bh=8nTyu7ft5kxPfj092hxXwsQxWsYuWOIKbbZIwVfiYOE=; b=AxQlbbC0S7Zp1r4VwPVblJ2+5UIRJE6EmdC86kq7FTdSzY4opPPtIRUv9Apoaa37H4 Ti7GZKAx+gNeglbPTXp+C0A7uOpvbZUba2ixWEXITdbNWrIF0tbT5wcm8dXCNrypCZKd kImcp8TNJOFaTsWOLZlfzilF2nKY29xzWls85kUNbK6PmbIJp97R1gF7azVCE/wMm4zZ j5zFTEgKOMYTNnB5LEFTfWoyITKl21mSVLs+rTq6gmZ7re2v3ZvwHTdGvkQnHzZ7FwQI BPLyTtUjtA1kN0V07n9yg6+uFVjKF6apAGbD3EADmEJhd49ulVsLeG2EmBmztFrKj41r WHrw== Received: by 10.66.82.230 with SMTP id l6mr29611476pay.12.1355079715745; Sun, 09 Dec 2012 11:01:55 -0800 (PST) Received: from [192.168.1.102] (c-69-181-249-16.hsd1.ca.comcast.net. [69.181.249.16]) by mx.google.com with ESMTPS id rk6sm7675268pbc.20.2012.12.09.11.01.54 (version=SSLv3 cipher=OTHER); Sun, 09 Dec 2012 11:01:55 -0800 (PST) Message-ID: <1355079715.3896.14.camel@jdavis> Subject: init_htab causes SIGFPE (or worse) due to miscalculation for large nbuckets From: Jeff Davis To: pgsql-bugs@postgresql.org Date: Sun, 09 Dec 2012 11:01:55 -0800 Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit Mime-Version: 1.0 X-Gm-Message-State: ALoCoQkuZuBxAT8tqb2his0CsK+iCZCjTKPvVlJ0XATxpMsavV2pSgpw71pgUXoJzFQM+Ee6G9Ja X-Pg-Spam-Score: -2.6 (--) 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 If nbuckets is around 2^30+1, which can happen if work_mem is very high, then: nbuckets = 1 << my_log2(lnbuckets); ends up as 1 << 31, which is negative, leading to a SIGFPE on my machine, but I think it can also lead to an infinite loop or a crash (after corrupting the HASHHDR). The only simple way I can reproduce this is with gdb: 1. attach gdb to a session 2. set a breakpoint in ExecInitRecursiveUnion and continue 3. execute in session: set work_mem='100GB'; with recursive r (i) as (select 1 union select i+1 from r where i < 10) select * from r; 4. (gdb) set node->numGroups = (1 << 30) + 1 5. (gdb) continue I think we should just cap nbuckets at 1 << 30 in init_htab. There was a previous fix here: http://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=299d1716525c659f0e02840e31fbe4dea3 But it assumed that init_htab could deal with INT_MAX. In practice, work_mem will usually be the limiting factor anyway, but not if it's set high. Regards, Jeff Davis -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs