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

refactor: Use u64 over size_t for all cache sizes to fix a 32-bit overflow

Public commit record

What the developer wrote

Authored by MarcoFalke

100/100 · Strong
refactor: Use u64 over size_t for all cache sizes to fix a 32-bit overflow

This is a refactor on 64-bit systems, because size_t is equal to u64.

However, on 32-bit systems, it fixes an integer overflow while calculating the cache sizes:

src/node/caches.cpp:71:49: runtime error: unsigned integer overflow: 471859200 * 10 cannot be represented in type size_t (aka "unsigned int")

This happens while multiplying the default cache size (450MiB) by 10:

index_sizes.tx_index = std::min(total_cache * 10 / 100, ...)
^^^^^^^^^^^^^^^^

The issue was introduced in commit d06dabf26bea7d9ca8d635e8338f64aec74c56a8.

====

Also, add missing includes in touched files, according to IWYU.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Uses a recognizable type or scope✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This commit fixes a bug in Bitcoin Core that only affects 32-bit computers. When the program calculated how much database cache to allocate, it multiplied a large default cache value by 10. On 32-bit systems that multiplication overflowed, producing a much smaller or incorrect number. The fix changes the internal type from size_t (32-bit on 32-bit systems) to uint64_t (always 64-bit) so the multiplication stays correct. On normal 64-bit computers the change is harmless and just a cleanup.

Recommended action

Apply the patch. If running 32-bit Bitcoin Core builds, prioritize upgrading to a release containing this fix, because the overflow can silently corrupt cache allocation decisions. No immediate emergency response is needed for 64-bit deployments, but the change is safe to include.

Security signals we found

01

Integer overflow in cache-size calculation on 32-bit systems

02

Unsigned multiplication overflow explicitly mentioned in commit message with runtime sanitizer output

03

Type promotion from size_t to uint64_t to prevent platform-dependent width issues

04

Default cache value 450 MiB multiplied by 10 exceeds 32-bit size_t range

Risk score

Why this scored 43/100

Our methodology →
Potential impact 12/30
Exploitability 5/25
Stealth signal 6/15
Affected reach 8/15
Confidence 8/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.