tblockchain.py: check header length - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 0180abc1791a169cd6c493a922900b143492bb6e DIR parent 9a0cf6376989d72f297a3fb744f19912c24275b5 HTML Author: SomberNight <somber.night@protonmail.com> Date: Thu, 5 Apr 2018 16:12:34 +0200 blockchain.py: check header length related: #4212 Diffstat: M lib/blockchain.py | 6 ++++++ 1 file changed, 6 insertions(+), 0 deletions(-) --- DIR diff --git a/lib/blockchain.py b/lib/blockchain.py t@@ -40,6 +40,10 @@ def serialize_header(res): return s def deserialize_header(s, height): + if not s: + raise Exception('Invalid header: {}'.format(s)) + if len(s) != 80: + raise Exception('Invalid header length: {}'.format(len(s))) hex_to_int = lambda s: int('0x' + bh2u(s[::-1]), 16) h = {} h['version'] = hex_to_int(s[0:4]) t@@ -255,6 +259,8 @@ class Blockchain(util.PrintError): with open(name, 'rb') as f: f.seek(delta * 80) h = f.read(80) + if len(h) < 80: + raise Exception('Expected to read a full header. This was only {} bytes'.format(len(h))) elif not os.path.exists(util.get_headers_dir(self.config)): raise Exception('Electrum datadir does not exist. Was it deleted while running?') else: