From e495c90ee41009ab9c6a5c42425c4cf599188e19 Mon Sep 17 00:00:00 2001 From: 5mil <5mil@users.noreply.github.com> Date: Fri, 11 Mar 2016 09:41:35 -0500 Subject: [PATCH] Code fix fix for these issues https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2015-July/009697.html --- src/key.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/key.cpp b/src/key.cpp index e40cd53f457..adf67ad0a04 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -354,8 +354,29 @@ bool CKey::SetCompactSignature(uint256 hash, const std::vector& v return false; } -bool CKey::Verify(uint256 hash, const std::vector& vchSig) +bool CKey::Verify(uint256 hash, const std::vector& vchSigParam) { + // Prevent the problem described here: https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2015-July/009697.html + // by removing the extra length bytes + std::vector vchSig(vchSigParam.begin(), vchSigParam.end()); + if (vchSig.size() > 1 && vchSig[1] & 0x80) + { + unsigned char nLengthBytes = vchSig[1] & 0x7f; + + if (vchSig.size() < 2 + nLengthBytes) + return false; + + if (nLengthBytes > 4) + { + unsigned char nExtraBytes = nLengthBytes - 4; + for (unsigned char i = 0; i < nExtraBytes; i++) + if (vchSig[2 + i]) + return false; + vchSig.erase(vchSig.begin() + 2, vchSig.begin() + 2 + nExtraBytes); + vchSig[1] = 0x80 | (nLengthBytes - nExtraBytes); + } + } + if (vchSig.empty()) return false;