3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 15:22:16 +00:00

Script: clone tx before performing correctlySpends check. This prevents thread safety issues and corrupted transactions if validation fails.

This commit is contained in:
Mike Hearn 2013-10-07 18:09:38 +02:00
parent 9953bbe5cb
commit 1f7dd9495e

View File

@ -1168,6 +1168,13 @@ public class Script {
*/
public void correctlySpends(Transaction txContainingThis, long scriptSigIndex, Script scriptPubKey,
boolean enforceP2SH) throws ScriptException {
// Clone the transaction because executing the script involves editing it, and if we die, we'll leave
// the tx half broken (also it's not so thread safe to work on it directly.
try {
txContainingThis = new Transaction(txContainingThis.getParams(), txContainingThis.bitcoinSerialize());
} catch (ProtocolException e) {
throw new RuntimeException(e); // Should not happen unless we were given a totally broken transaction.
}
if (getProgram().length > 10000 || scriptPubKey.getProgram().length > 10000)
throw new ScriptException("Script larger than 10,000 bytes");