Skip to content

Commit 549c696

Browse files
CVE-2017-12842 mitigation
1 parent 6ea6ee3 commit 549c696

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

src/consensus/tx_check.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <consensus/tx_check.h>
6+
#include <xep/consensus/tx_check.h>
67

78
#include <consensus/amount.h>
89
#include <primitives/transaction.h>
@@ -16,9 +17,13 @@ bool CheckTransaction(const CTransaction& tx, TxValidationState& state)
1617
if (tx.vout.empty())
1718
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-vout-empty");
1819
// Size limits (this doesn't take the witness into account, as that hasn't been checked for malleability)
19-
if (::GetSerializeSize(TX_NO_WITNESS(tx)) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT) {
20+
const size_t size = ::GetSerializeSize(TX_NO_WITNESS(tx));
21+
if (size * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT) {
2022
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-oversize");
2123
}
24+
if (!XEP_CheckTransactionSize(state, size)) {
25+
return false;
26+
}
2227

2328
// Check for negative or overflow output values (see CVE-2010-5139)
2429
CAmount nValueOut = 0;

src/test/data/tx_invalid.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "-1 CHECKLOCKTIMEVERIFY"]],
150150
"01000000010001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000065cd1d", "CHECKLOCKTIMEVERIFY"],
151151
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "1"]],
152-
"010000000100010000000000000000000000000000000000000000000000000000000000000000000004005194b1010000000100000000000000000002000000", "CHECKLOCKTIMEVERIFY"],
152+
"01000000010001000000000000000000000000000000000000000000000000000000000000000000000500005194b1010000000100000000000000000002000000", "CHECKLOCKTIMEVERIFY"],
153153

154154
["Input locked"],
155155
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "0 CHECKLOCKTIMEVERIFY 1"]],

src/validation.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -794,10 +794,6 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
794794
return state.Invalid(TxValidationResult::TX_NOT_STANDARD, reason);
795795
}
796796

797-
// Transactions smaller than 65 non-witness bytes are not relayed to mitigate CVE-2017-12842.
798-
if (::GetSerializeSize(TX_NO_WITNESS(tx)) < MIN_STANDARD_TX_NONWITNESS_SIZE)
799-
return state.Invalid(TxValidationResult::TX_NOT_STANDARD, "tx-size-small");
800-
801797
// Only accept nLockTime-using transactions that can be mined in the next
802798
// block; we don't want our mempool filled up with transactions that can't
803799
// be mined yet.

src/xep/consensus/tx_check.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2020-2025 The XEP Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef ELECTRAPROTOCOL_CONSENSUS_TX_CHECK_H
6+
#define ELECTRAPROTOCOL_CONSENSUS_TX_CHECK_H
7+
8+
#include <consensus/validation.h>
9+
10+
bool XEP_CheckTransactionSize(TxValidationState& state, size_t size)
11+
{
12+
// 64-byte transactions are rejected to mitigate CVE-2017-12842
13+
if (size == 64) {
14+
return state.Invalid(TxValidationResult::TX_CONSENSUS, "tx-size-small");
15+
} else {
16+
return true;
17+
}
18+
};
19+
20+
#endif // ELECTRAPROTOCOL_CONSENSUS_TX_CHECK_H

0 commit comments

Comments
 (0)