Skip to content

Commit a6f33ea

Browse files
committed
Sanity-check script sizes in bitcoin-tx
1 parent 57ee739 commit a6f33ea

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/bitcoin-tx.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s
387387
scriptPubKey = GetScriptForWitness(scriptPubKey);
388388
}
389389
if (bScriptHash) {
390+
if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
391+
throw std::runtime_error(strprintf(
392+
"redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
393+
}
390394
// Get the ID for the script, and then construct a P2SH destination for it.
391395
scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey));
392396
}
@@ -447,10 +451,19 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& str
447451
bScriptHash = (flags.find("S") != std::string::npos);
448452
}
449453

454+
if (scriptPubKey.size() > MAX_SCRIPT_SIZE) {
455+
throw std::runtime_error(strprintf(
456+
"script exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_SIZE));
457+
}
458+
450459
if (bSegWit) {
451460
scriptPubKey = GetScriptForWitness(scriptPubKey);
452461
}
453462
if (bScriptHash) {
463+
if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
464+
throw std::runtime_error(strprintf(
465+
"redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
466+
}
454467
scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey));
455468
}
456469

0 commit comments

Comments
 (0)