diff -uNr a/bitcoin/src/main.cpp b/bitcoin/src/main.cpp --- a/bitcoin/src/main.cpp 1f0735d2cee2f9ca2a177aead4ecc7a1371d59c4375aedb172ee99c28b02fa28e664decec9580a510bfca4738d85e377fb74396fe4979b75adbe1a3ec92b01c9 +++ b/bitcoin/src/main.cpp 8d726cc72e81befff25d5872e757975c5ee538a6f51a930493fff9b435e4458c736401907fa5d589368cb4a4862614e6fe16ea30cfd568184916733289477a1b @@ -1877,6 +1877,9 @@ return error("message getdata size() = %d", vInv.size()); } + // Counter of bytes sent in response to this 'getdata' command + unsigned int sentBytes = 0; + BOOST_FOREACH(const CInv& inv, vInv) { if (fShutdown) @@ -1891,6 +1894,17 @@ { CBlock block; block.ReadFromDisk((*mi).second); + + // Add block's size to sentBytes, and determine if reached limit + sentBytes += block.GetSerializeSize(SER_NETWORK); + if (sentBytes >= SendBufferSize()) + { + printf("getdata (block) may not transmit %u bytes\n", sentBytes); + pfrom->Misbehaving(20); + break; + } + + // Limit not reached, so permitted to send block pfrom->PushMessage("block", block); // Trigger them to send a getblocks request for the next batch of inventory