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.96) (envelope-from ) id 1wC4RA-001dUn-2u for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Apr 2026 23:41:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wC4R9-003UJ5-0y for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Apr 2026 23:41:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wC4R9-003UIw-03 for pgsql-hackers@lists.postgresql.org; Sun, 12 Apr 2026 23:41:55 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wC4R7-00000000kFx-43Kl for pgsql-hackers@lists.postgresql.org; Sun, 12 Apr 2026 23:41:55 +0000 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-43d7650202fso415343f8f.2 for ; Sun, 12 Apr 2026 16:41:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776037312; cv=none; d=google.com; s=arc-20240605; b=cP9Y9p4vwV1YP2xrWtmTJS/ihDQ25+QnS5g/QYouj2z/Ze5EAGM7TICfG2arxXTq91 zitIIJ2Pf+lgVLeCdfq757hDKon4brIVRhUkFQ8rKYnxi991ZeX6w1pOpP7ZibacXV1O poH2UhYB0yNA5N1ucEkSsHFEBKzRVXgfUEUVU3WOcRL3m1z9fUvNVoHd3SBK7eN9OZQb FrijZ0JW0tFwI1G4ls+YGdWbET5RhKLRWcw4CuM+SEUUby1cBo1tGptpQEGllbGc9diV BeQUui1Z+D2jDm4ylm/Ed0c1LRAwwlDYnfafXUJyEv3AAD/BDr5akmj4tfcl4Cz8zRx7 TnMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=6G3MXpntgoMmoho8QCOnYsZ1sGLM+klp8aozfgtg4Eg=; fh=lK8Ey75qlt4w4S087HA2sQsiHJBeqk3Wvx6fjumIn6g=; b=kCKncKCDsDfa+XP+Zdqlb3EuOzNNbzRDuPAcMeZ2cHNhR3nZqokmEBgndxrf1Dqqtw ReUzEudVMy+oI3R90f+jHbU0lpnVsDcqAqkmQAcSOS1bmG8S/Zxf4LB4IBmACIdK2hve vsV8skh3wbx0aO7GgB1RwCnMmS1uMAIuU/VJHVQXHXkGF3Go5BabSp/DPkZPvSaMRIL2 b9j8LNkfYZazwyIzMYlB06YnUdB7b+4p8xUwO8fN8mYTCv+1d+uz9NRuUp42WHcsQkdR z3WOSbxTTMX44G463rotK81+2wsmW1LNf2wMlolZ8w++4DkYYB6dQrwhGzCcjKOC1erg Iigw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776037312; x=1776642112; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=6G3MXpntgoMmoho8QCOnYsZ1sGLM+klp8aozfgtg4Eg=; b=Eta3i/ZuOijZNb76m2sFlPoOTFzNC3rStjM2+TGp75uRd2zgNu+fXamWfHHxP4XZLO wdN1AjuS5Yz0b6DSI2kxnou4ya60gltlUJxuIpSZE0XG+wTBQV36qZbB2rUcxSiYNQ5x yB8KCSbwP1/6tJDNJ54mpWcHfuL1i1bR/eU7bpGCphlvbBkxAMasfC5/qTVDAqHv+2wE kEF0jZZPaNDWgmXQIlrv664lv5DJvD/wJCRiK1aYwRmqmx968oxvdUOlWpeccWjFztJF txPqMpTXQVJ+U1rdR+E+f3R2QlvOwKPrdeDeXcloznfb25lN6sVJZBFXRiqKXUPVOOXX yTSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776037312; x=1776642112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6G3MXpntgoMmoho8QCOnYsZ1sGLM+klp8aozfgtg4Eg=; b=hbZ4Rz+iXOZhAUjjoJ/ef1sV0R+bB8DG7rVoE75ohKZPOmwOOAwRy/QrIURermllHe 7nIKGb/xxvaNTqucXmevbq8+sgHFNftRhhUsPg9ViodZgjIjMpyPxqIoAGGIMDiyCdMv /KygJSvi/uruahcfbvG7L7sHffVfAHtyTysCLInhUxWA3RGUG97trfLxQT/m4itK2IP4 +pN/qQVIdt25UAvq3e9WyAPrm/cKclzZD4qqQcmMSuTLaD5NOoZ3EFyAARcUn3FINhwH i4w7ro4bBSqikHO+HUK4z/ck8WkL+SGopA2ip1Is4Ji4bQpR9XaxiZF0/HQHe497P5S7 KNiA== X-Gm-Message-State: AOJu0YwT8qmy7EAt9LWZgCGEc5C/hnrOtgjQSUEpD3zWJGAkfMQcMGOA dOmpmhhBBPTnqgZ1Cc+gN+3dc/AuPvgG583h6Hjb7Iw8rqI3aw62+Z3iipe17iVByQMofSHeyyQ B9jPi7mXdlKlpT3mTy5YLQxPnHbnDSzGXwg== X-Gm-Gg: AeBDiet3YWCjsSIlmfKZQhSV+oEXmsizPLquuDP7DhtX2n/RnkA96RYIKHU/ATKKI+f gndYZzrB3Ny8bA7DcoMKZYO19dOtG1QOxOB/Y6iXzqB7zLigaaBqAv7Sqr9wDivPC3r1zBLj/VG upc5AhUbArZa6lsCScTpojuB1I+4k0rptKx80XAh4vQdXGY1TCHju1MQC4vWCYWiV9rOVDvQ/o8 3Mv9tZjfC0iNsrrZUsbb3dl+Z82P3gwpSDPAvQ0bfY0L6yvJAE+hjPc2ITpGDO4Kmluf1aCL4XL PvNecDumXWyBAAAuRm7Tm8g7k6jCx9Nvok0YuXk+k+CesjE/SpPE9PF1rYjo0J3jXqknKncDng= = X-Received: by 2002:a5d:4443:0:b0:43d:696b:72a6 with SMTP id ffacd0b85a97d-43d696b7352mr7890530f8f.7.1776037312430; Sun, 12 Apr 2026 16:41:52 -0700 (PDT) MIME-Version: 1.0 References: <3190647.1775103768@sss.pgh.pa.us> In-Reply-To: From: David Rowley Date: Mon, 13 Apr 2026 11:41:40 +1200 X-Gm-Features: AQROBzAh8Zt6qPRxpF2MBreUwID484IU55pTSb1iw7juQTVQwtqlTPfT9HfHBWY Message-ID: Subject: Re: Small and unlikely overflow hazard in bms_next_member() To: Tom Lane Cc: PostgreSQL Developers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 13 Apr 2026 at 01:17, David Rowley wrote: > Re-thinking this after a week's holiday, it seems fine to use an > unsigned 32-bit int rather than a 64-bit int to fix this bug. I'd > previously been uncertain if there were any guarantees in C to what > (unsigned int) -1 would return, but going by [1] at 6.3.1.3, it says: > > "Otherwise, if the new type is unsigned, the value is converted by > repeatedly adding or subtracting one more than the maximum value that > can be represented in the new type until the value is in the range of > the new type." > > So, it seems even on one's complement that -1 as an unsigned int will > be UINT_MAX. When we add 1 to UINT_MAX, we're guaranteed to get 0, as > it's unsigned maths and overflows are going to result in a value > modulus the max value for the type. I've pushed that version. No backpatch. David