diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 2aabdc199172..f61add3b6d95 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -5524,7 +5524,13 @@ void PeerManagerImpl::ProcessMessage( if (msg_type == NetMsgType::SPORK) { CSporkMessage spork; - vRecv >> spork; + try { + vRecv >> spork; + } catch (const std::ios_base::failure& e) { + // Attribute deserialization failures to the peer; the outer catch would otherwise silently drop. + Misbehaving(*peer, 100, strprintf("malformed spork received. peer=%d error=%s", pfrom.GetId(), e.what())); + return; + } uint256 hash = spork.GetHash(); CInv spork_inv{MSG_SPORK, hash}; diff --git a/src/spork.h b/src/spork.h index bb1c03bef74b..9d23fa68b240 100644 --- a/src/spork.h +++ b/src/spork.h @@ -109,7 +109,8 @@ class CSporkMessage SERIALIZE_METHODS(CSporkMessage, obj) { - READWRITE(obj.nSporkID, obj.nValue, obj.nTimeSigned, obj.vchSig); + READWRITE(obj.nSporkID, obj.nValue, obj.nTimeSigned, + LIMITED_VECTOR(obj.vchSig, CPubKey::COMPACT_SIGNATURE_SIZE)); } /** diff --git a/test/functional/feature_sporks.py b/test/functional/feature_sporks.py index 7940c1aa9b86..522d8f7a58d9 100755 --- a/test/functional/feature_sporks.py +++ b/test/functional/feature_sporks.py @@ -3,6 +3,9 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. +import struct + +from test_framework.messages import ser_compact_size from test_framework.p2p import MESSAGEMAP, P2PInterface from test_framework.test_framework import BitcoinTestFramework @@ -117,6 +120,14 @@ def run_test(self): assert "" not in self.nodes[0].spork('show').keys() + # Oversized signature length prefix must trigger disconnect, not silent drop. + MAX_SIZE = 0x02000000 + bad_spork = msg_spork_raw() + bad_spork.raw = struct.pack("