AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 35 Bitcoin

Merge bitcoin/bitcoin#35818: bloom: avoid undefined sizing calculations

Public commit record

What the developer wrote

Authored by merge-script

91/100 · Strong
Merge bitcoin/bitcoin#35818: bloom: avoid undefined sizing calculations

c4302ddf806094fcc2b1e21593e25b2038191a07 fuzz: cover bloom sizing boundaries (Lőrinc)
3acd9ae9016e6c66783bec002435a49c04050db2 test: cover bloom sizing boundaries (Lőrinc)
77055771169dc44f832083f46468ea75421a009b bloom: avoid undefined sizing calculations (Lőrinc)
3614b38e33cb98528b0c3dc337060f7448bb8e6e test: characterize bloom filter sizing (Lőrinc)

Pull request description:

**Problem:** The four-argument `CBloomFilter` constructor is used by unit tests and the fuzz target to exercise Bloom filter sizing directly.
Zero elements make the hash-function calculation divide by zero.
The size calculation converts its floating-point result to `unsigned int` before applying the protocol limit, which is undefined for zero or invalid false-positive rates and for valid parameters whose calculated size exceeds the integer range.

**Fix:** Require false-positive rates in `[0, 1]`, construct the existing empty match-all state for zero elements, and use the largest permitted filter for a zero rate with positive elements.
Clamp the calculated size before its integer conversion so large valid inputs remain within the protocol limit.

ACKs for top commit:
rustaceanrob:
Code review ACK c4302ddf806094fcc2b1e21593e25b2038191a07
sedited:
ACK c4302ddf806094fcc2b1e21593e25b2038191a07
instagibbs:
ACK c4302ddf806094fcc2b1e21593e25b2038191a07

Tree-SHA512: 836d7a7602b4e508b57bc62fa93bff460a076155ca3973cdde9f0a5bcfc021573a72e8bf2e7477f2c6939074f0b959b6306ab55e929c8e704fab0d0b77734e12
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a bug in Bitcoin Core's Bloom filter constructor that could perform undefined math when given unusual inputs, such as zero elements or a zero/invalid false-positive rate. The fix adds input checks and special-case handling so the constructor no longer divides by zero, takes the logarithm of zero, or converts an out-of-range floating-point size to an integer. The affected constructor is used only in tests and fuzzing, not in normal peer-to-peer network code, so the practical risk to live Bitcoin nodes is low.

Recommended action

No immediate action is required for production nodes. Developers should ensure the patched constructor is used in all new tests and fuzz targets, and consider whether any other code paths construct CBloomFilter with user-controlled nElements/nFPRate values that could reach the fixed helper.

Security signals we found

01

Undefined behavior in size calculation: conversion of out-of-range double to unsigned int

02

Divide-by-zero in hash-function count when nElements is zero

03

log(0) / FE_DIVBYZERO when false-positive rate is zero

04

Missing validation of false-positive rate range and finiteness

05

Constructor used by fuzz target and unit tests, not by network deserialization path

Risk score

Why this scored 35/100

Our methodology →
Potential impact 8/30
Exploitability 5/25
Stealth signal 6/15
Affected reach 5/15
Confidence 7/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.