Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t5Syl-006G0k-QH for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Oct 2024 16:52:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t5Syj-008LJr-Fy for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Oct 2024 16:52:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t5Syj-008LIV-2Y for pgsql-hackers@lists.postgresql.org; Mon, 28 Oct 2024 16:52:29 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t5Syf-003Ihi-LZ for pgsql-hackers@postgresql.org; Mon, 28 Oct 2024 16:52:27 +0000 Received: from [192.168.1.110] (dsl-hkibng22-50ddb7-241.dhcp.inet.fi [80.221.183.241]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4XcfZB6fKnz49Q16; Mon, 28 Oct 2024 18:52:16 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1730134339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l0CERl+WNVtns26Mgq0NrYLCKFNz/Z6bhVqHMpyp/Yo=; b=sUzErIuGxCPIdZQdXny715T1U4vqw2wykGKB+a5wDgNzawujYsEXvsqyjIUrY83D+WpLKG +n9dVXtYo5iaCPHjlF0hy3uEDTzgSC4nyESILzoC5WKr11PeZee31VVNZ10RYXdcjPMlBr G6UbucUGJnxHQ2EgCTMPLji1fiiEJPz4XS0rIfqylpVMzNu3LmkeZyLqZgB2xB+La8IhdE 3zw3S5ibFkswDURXCnXjfcLsaOQFvawz7RY+EsgS6zbh7ulb/SEBChaZb5XtSMFvaxGAZS o64zxwilV/OwEXVGvq9ZmNybVTryNVVTLALZtR5R5hRLQbbAVm337XfhFWnB2Q== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1730134339; a=rsa-sha256; cv=none; b=f8Xj/yPkLJzUClyn4mYbHv+8Js3aKouB14llwH2aWPu/F1kxbBTEI8rahPJ8oFsUJx6b2i 7YHo13eSgF0VVYZluEt7Fg4KpAimR6jn+3xwQiz+XRdLMS58Yf+hvM4b9yKZzTMVEIb0Lm QinHUn+vTv7Mocw9XC2OFCo5pDhtt7pB/lpI/Vy2U06lSRz6+uEpGzvQHBhbqiIWivE8Z1 iGt8i1RjmcT+Ifs81EP9J58HQNGDXwpULmu5AEYXzD+6+GNvBMKmQgUAqv5c3eLfmNNMBj cMW6Wry1FEe65HLO/ETGtpVwDmHsRHN3OOXYZ0bfZP76ni8zvJRoa6rczHpWTw== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1730134339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l0CERl+WNVtns26Mgq0NrYLCKFNz/Z6bhVqHMpyp/Yo=; b=Tt+O3GhsN8/bOXeYcIVrdwQ52Xx1TADWSnYRn7RtN72W6++kUMZueBNtCJgp8iBP8SoJHP AthjNMaqhgnKNBa9wdzxnDrHszv6vGEG/PXM2wWhCBP/K/gEZaP5HtliJ7uY9dZGEXfL7N f8KWsb+3BzJR6uYK7ycaU/k4u5wLzpD4nfgBazyIG4SYHKu2btnU5LYh6b7Q4i4XUE1zoJ ohnM1IppCZuuE79o+Z9eYfiECFdugLEWic9BnlGsuGklT907o+0xplAmMnMVKl4OQJB7uR a4Bb4/m8YCLeqhCDbZh6CRmPfxMScBFHhGZCRsSIUSLzJeDJfwT/BWwGFMEDUQ== Message-ID: <08507458-8222-483c-9234-150d1a607efe@iki.fi> Date: Mon, 28 Oct 2024 18:52:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Avoid possible overflow (src/port/bsearch_arg.c) To: Tomas Vondra , Ranier Vilela , Nathan Bossart , Tomas Vondra Cc: Pg Hackers References: <54ee5b1f-bf75-48ea-b642-1ef275c1a093@vondra.me> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: <54ee5b1f-bf75-48ea-b642-1ef275c1a093@vondra.me> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 28/10/2024 17:30, Tomas Vondra wrote: >> Some of those other implementations have fixed this, others have not. >> And they all seem to also have the "involes" typo in the comment that we >> fixed in commit 7ef8b52cf07 :-). Ranier, you might want to submit this >> fix to those other projects too. > > Thanks for fixing this, although I wonder if we can actually hit this, > as we don't really allocate more than 1GB in most places. But it's > possible, and the pre-bfa2cee code handled it fine. Yeah, I didn't check closely I'm pretty sure none of the current callsites can pass anything near INT_MAX elements. While we're at it, there's this in dicts/spell.h: > /* > * Structure to store Hunspell options. Flag representation depends on flag > * type. These flags are about support of compound words. > */ > typedef struct CompoundAffixFlag > { > union > { > /* Flag name if flagMode is FM_CHAR or FM_LONG */ > const char *s; > /* Flag name if flagMode is FM_NUM */ > uint32 i; > } flag; > /* we don't have a bsearch_arg version, so, copy FlagMode */ > FlagMode flagMode; > uint32 value; > } CompoundAffixFlag; We have bsearch_arg() now, so we could switch to that and remove 'flagMode' from here. -- Heikki Linnakangas Neon (https://neon.tech)