Repository navigation
Conversation
Compressor::decompress() trusts the region it is given. In
Node::getBlockReply that region, and its binary size, are read straight from
a peer's packet (operator>>(IDataStream&, CompressedRegion&)), so one packet
can take down a syncing node:
- binarySize is an arbitrary size_t. bytes.resize(binarySize) throws
std::length_error/std::bad_alloc, nothing on the transport thread catches
it, and the node terminates.
- An empty region (data() == nullptr, size() == 0) takes the "not compressed"
branch with size = 0 - 1 and reads from nullptr + 1: SIGSEGV.
Reject both before touching memory and return T{}, as decompress() already
does when LZ4 fails. Callers already handle an empty result ("No pools
found").
- An empty region is rejected.
- A compressed region is rejected when binarySize exceeds INT_MAX (LZ4 works
with int sizes) or 256 x the compressed size. LZ4 cannot expand data more
than 255:1, so no region produced by compress() is affected.
Tests (tests/csnode/compressor_tests.cpp):
- Compressor.RejectsBinarySizeLz4CannotProduce: before the fix it throws
std::bad_alloc.
- Compressor.RejectsEmptyRegion: before the fix it crashes with SIGSEGV.
nodetests: 112/112 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
cs::Compressor::decompress()trusts the region it is given. InNode::getBlockReplythe region and its declared binary size come from a peer's message, so a malformed block reply can make a syncing node attempt an allocation of an arbitrary size (an uncaught exception that ends the process) or read through a null pointer, before anything in it is verified. Found while auditing the node and reported to the Credits team.What changes
csnode/include/csnode/compressor.hpp,Compressor::decompress()returns an empty result, as it already does when LZ4 fails, for:INT_MAX(LZ4 works withintsizes) or 256 times the compressed size (LZ4 cannot expand data more than 255:1).Callers already handle an empty result ("No pools found").
Effect on the network
None for honest traffic: no region produced by
Compressor::compress()is affected, so every valid block reply decompresses exactly as before. Only malformed input is refused.Tests
tests/csnode/compressor_tests.cpp:Compressor.RejectsBinarySizeLz4CannotProduce(threwstd::bad_allocbefore) andCompressor.RejectsEmptyRegion(crashed before). Built and run on 4a95aaa (GCC 13).Same change in the community fork: CreditsCommunity#4, running on mainnet community nodes.