@@ -31,8 +31,6 @@ CBloomFilter::CBloomFilter(const unsigned int nElements, const double nFPRate, c
3131 * Again, we ignore filter parameters which will create a bloom filter with more hash functions than the protocol limits
3232 * See https://en.wikipedia.org/wiki/Bloom_filter for an explanation of these formulas
3333 */
34- isFull(false ),
35- isEmpty(true ),
3634 nHashFuncs(std::min((unsigned int )(vData.size() * 8 / nElements * LN2), MAX_HASH_FUNCS)),
3735 nTweak(nTweakIn),
3836 nFlags(nFlagsIn)
@@ -47,15 +45,14 @@ inline unsigned int CBloomFilter::Hash(unsigned int nHashNum, const std::vector<
4745
4846void CBloomFilter::insert (const std::vector<unsigned char >& vKey)
4947{
50- if (isFull )
48+ if (vData. empty ()) // Avoid divide-by-zero (CVE-2013-5700 )
5149 return ;
5250 for (unsigned int i = 0 ; i < nHashFuncs; i++)
5351 {
5452 unsigned int nIndex = Hash (i, vKey);
5553 // Sets bit nIndex of vData
5654 vData[nIndex >> 3 ] |= (1 << (7 & nIndex));
5755 }
58- isEmpty = false ;
5956}
6057
6158void CBloomFilter::insert (const COutPoint& outpoint)
@@ -74,10 +71,8 @@ void CBloomFilter::insert(const uint256& hash)
7471
7572bool CBloomFilter::contains (const std::vector<unsigned char >& vKey) const
7673{
77- if (isFull )
74+ if (vData. empty ()) // Avoid divide-by-zero (CVE-2013-5700 )
7875 return true ;
79- if (isEmpty)
80- return false ;
8176 for (unsigned int i = 0 ; i < nHashFuncs; i++)
8277 {
8378 unsigned int nIndex = Hash (i, vKey);
@@ -112,10 +107,8 @@ bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx)
112107 bool fFound = false ;
113108 // Match if the filter contains the hash of tx
114109 // for finding tx when they appear in a block
115- if (isFull)
110+ if (vData. empty ()) // zero-size = "match-all" filter
116111 return true ;
117- if (isEmpty)
118- return false ;
119112 const uint256& hash = tx.GetHash ();
120113 if (contains (hash))
121114 fFound = true ;
@@ -177,19 +170,6 @@ bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx)
177170 return false ;
178171}
179172
180- void CBloomFilter::UpdateEmptyFull ()
181- {
182- bool full = true ;
183- bool empty = true ;
184- for (unsigned int i = 0 ; i < vData.size (); i++)
185- {
186- full &= vData[i] == 0xff ;
187- empty &= vData[i] == 0 ;
188- }
189- isFull = full;
190- isEmpty = empty;
191- }
192-
193173CRollingBloomFilter::CRollingBloomFilter (const unsigned int nElements, const double fpRate)
194174{
195175 double logFpRate = log (fpRate);
0 commit comments