From 8719c94c33a00e51c6100c06f3bc229613572de9 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 23 Aug 2018 17:01:14 -0700 Subject: [PATCH] Disallow extended encoding for non-witness transactions --- src/primitives/transaction.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index c1e92f2ecb..91a1d81984 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -654,6 +654,10 @@ inline void UnserializeTransaction(TxType& tx, Stream& s) { const_cast(&tx.wit)->vtxinwit.resize(tx.vin.size()); const_cast(&tx.wit)->vtxoutwit.resize(tx.vout.size()); s >> tx.wit; + if (!tx.HasWitness()) { + /* It's illegal to encode witnesses when all witness stacks are empty. */ + throw std::ios_base::failure("Superfluous witness record"); + } } if (flags) { /* Unknown flag in the serialization */