Skip to content

csdb: reject pools whose hashing length points past their data (OOB read) - #5

Merged
EnzinoBB merged 1 commit into
masterfrom
fix/pool-validate-hashing-length
Oct 8, 2026
Merged

EnzinoBB merged 1 commit into
masterfrom
fix/pool-validate-hashing-length

Conversation

@EnzinoBB

@EnzinoBB EnzinoBB commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Problem: out-of-bounds read on block data received from the network

Pool::from_binary(), Pool::hash_from_binary() and Pool::from_lz4_byte_stream() read hashingLength_ from the bytes being parsed, then updateHash() hashes that many bytes. Nothing checked that the length fits inside the data.

A peer-supplied block (e.g. a BlockReply while syncing) with a huge hashing length makes the node read past its buffer: SIGSEGV, or a hash computed over unrelated memory.

Fix (csdb/src/pool.cpp, +16/-2)

Such data is rejected in the three entry points that know the full buffer size, with the same result as any other parse error: an invalid Pool or an empty PoolHash.

A legitimate block cannot be affected: by construction, hashingLength_ is the size of the block's own serialised prefix (Pool::priv::put), so it is always smaller than the data.

The check cannot live in get_hashed_data(), because ibstream::size() is the number of bytes still unread, not the total. A first attempt there rejected valid blocks, and the PoolCache serialisation tests caught it. That is also why this PR adds a test that must accept a legitimate block.

Tests (tests/csnode/pool_tests.cpp)

Test Before After
Pool.RejectsHashingLengthPastData SIGSEGV ✅
Pool.AcceptsSerializedPool (false-positive guard) ✅ ✅
full nodetests — 112/112

Upstream

A single commit that applies as is to CREDITSCOM/node, where pool.cpp is identical. It is independent of PR #4 (Compressor), although together they close the BlockReply -> crash path.

🤖 Generated with Claude Code

Pool::from_binary(), Pool::hash_from_binary() and
Pool::from_lz4_byte_stream() read hashingLength_ from the bytes being parsed,
then updateHash() hashes hashingLength_ bytes of them. Nothing checked that
the length fits, so a peer-supplied block (e.g. a BlockReply while syncing)
with a large hashing length makes the node read past the buffer: SIGSEGV,
or a hash over unrelated memory.

Reject such data in the three entry points that know the full buffer size,
with the same result as any other parse error: an invalid Pool or an empty
PoolHash.

A legitimate pool cannot be affected: hashingLength_ is, by construction, the
size of the pool's own serialized prefix (Pool::priv::put), so it is always
smaller than the pool's data.

Note: the check cannot live in get_hashed_data(), because ibstream::size()
is the number of bytes still unread, not the total size. A first attempt
there rejected valid pools, and the PoolCache serialization tests caught it.

Tests (tests/csnode/pool_tests.cpp):
- Pool.RejectsHashingLengthPastData: before the fix it crashes with SIGSEGV.
- Pool.AcceptsSerializedPool: guards against rejecting valid pools.
nodetests: 112/112 pass.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@EnzinoBB
EnzinoBB merged commit f781385 into master Oct 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant