From c9826221fbb51ce29a6d600c32b5cbe02fe34e99 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 16 Feb 2015 02:39:57 +1100 Subject: [PATCH] scripts: catch error in Script.fromBuffer --- src/script.js | 1 - src/scripts.js | 8 +++++++- test/fixtures/scripts.json | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/script.js b/src/script.js index e6c6aaad3..812970e1a 100644 --- a/src/script.js +++ b/src/script.js @@ -29,7 +29,6 @@ Script.fromASM = function(asm) { Script.fromBuffer = function(buffer) { var chunks = [] - var i = 0 while (i < buffer.length) { diff --git a/src/scripts.js b/src/scripts.js index 52824cd90..4ad20a9fd 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -70,7 +70,13 @@ function isScriptHashInput(script, allowIncomplete) { if (!Buffer.isBuffer(lastChunk)) return false var scriptSig = Script.fromChunks(script.chunks.slice(0, -1)) - var scriptPubKey = Script.fromBuffer(lastChunk) + var scriptPubKey + + try { + scriptPubKey = Script.fromBuffer(lastChunk) + } catch (e) { + return false + } return classifyInput(scriptSig, allowIncomplete) === classifyOutput(scriptPubKey) } diff --git a/test/fixtures/scripts.json b/test/fixtures/scripts.json index 442c4a9c4..e79a6e76a 100644 --- a/test/fixtures/scripts.json +++ b/test/fixtures/scripts.json @@ -111,6 +111,10 @@ { "description": "redeemScript not data", "scriptSig": "OP_0 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501 OP_RESERVED" + }, + { + "description": "signature forms invalid script", + "scriptSig": "OP_0 3045022100e12b17b3a4c80c401a1687487bd2bafee9e5f1f8f1ffc6180ce186672ad7b43a02205e316d1e5e71822f5ef301b694e578fa9c94af4f5f098c952c833f4691307f4e01" } ], "isPubKeyInput": [