Skip to content

Commit 89cc4f9

Browse files
author
MarcoFalke
committed
Merge #11554: Sanity-check script sizes in bitcoin-tx
a6f33ea Sanity-check script sizes in bitcoin-tx (Matt Corallo) Pull request description: Tree-SHA512: bb8ecb628763af23816ab085758f6140920a6ff05dcb298129c2bbe584a02a759c700a05740eca77023292c98a5658b2a608fa27d5a948d183f87ed9ab827952
2 parents 87d90ef + a6f33ea commit 89cc4f9

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)