From 71ce7cce6d192ac7dc7c4efc2240c9022b7b4ba6 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Tue, 12 Jun 2018 10:51:51 +0200 Subject: [PATCH] stricter tx deserialization: forbid junk at the end --- lib/transaction.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/transaction.py b/lib/transaction.py index b422a944c..6fdd60800 100644 --- a/lib/transaction.py +++ b/lib/transaction.py @@ -103,6 +103,11 @@ class BCDataStream(object): except IndexError: raise SerializationError("attempt to read past end of buffer") + def can_read_more(self) -> bool: + if not self.input: + return False + return self.read_cursor < len(self.input) + def read_boolean(self): return self.read_bytes(1)[0] != chr(0) def read_int16(self): return self._read_num(' dict: txin = d['inputs'][i] parse_witness(vds, txin, full_parse=full_parse) d['lockTime'] = vds.read_uint32() + if vds.can_read_more(): + raise SerializationError('extra junk at the end') return d