Repository navigation
Conversation
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>
Pool::priv::getTransactions() and getNewWallets() reserve() as many elements as the uint32 count read from the data. A peer-supplied block (e.g. a BlockReply while syncing) with a count near 2^32 asks for tens of GB: std::bad_alloc/length_error escapes the transport thread and the node terminates. Reserve at most the number of bytes still unread, because every element takes at least one of them. For valid data this reserves exactly what it did before. For forged data the parse loop fails at the first missing element, as it already did, and the pool is invalid. The other counts in Pool parsing are uint8, so they are left as they are. Tests (tests/csnode/pool_tests.cpp): - Pool.HugeTransactionsCountDoesNotAllocate: before the fix from_binary throws. - Pool.HugeNewWalletsCountDoesNotAllocate: before the fix from_binary throws. nodetests: 116/116 pass. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this PR
Two fields of a serialized block are trusted before they are checked against the data actually received. A block from a peer (a block reply while syncing) can therefore make the node read past its buffer when the block hash is computed, or reserve memory for far more transactions or new wallets than the data can hold, which ends the process with an uncaught exception. Found while auditing the node and reported to the Credits team.
What changes
csdb/src/pool.cpp:Pool::priv::hashingLengthFits():Pool::from_binary(),Pool::hash_from_binary()andPool::from_lz4_byte_stream()reject data whose hashing length exceeds its size, with the result of any other parse error (an invalidPool, an emptyPoolHash). The check cannot live inget_hashed_data(), where the stream size is the unread remainder.getTransactions()andgetNewWallets()reserve at most as many elements as bytes remain to parse (every element takes at least one byte). The parse loop already fails at the first missing element.Effect on the network
None for honest traffic: the hashing length of a valid pool is the size of its own serialized prefix, and for valid data the reserve is exactly what it was. Every valid block parses and hashes as before; only malformed blocks are refused.
Tests
tests/csnode/pool_tests.cpp:Pool.RejectsHashingLengthPastData(crashed before),Pool.AcceptsSerializedPool,Pool.HugeTransactionsCountDoesNotAllocateandPool.HugeNewWalletsCountDoesNotAllocate(threw before). Built and run on 4a95aaa (GCC 13).Same change in the community fork: CreditsCommunity#5 and #7, running on mainnet community nodes.