Skip to content

Commit

Permalink
scripts: catch error in Script.fromBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Feb 15, 2015
1 parent 4bcd169 commit c982622
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/script.js
Expand Up @@ -29,7 +29,6 @@ Script.fromASM = function(asm) {

Script.fromBuffer = function(buffer) {
var chunks = []

var i = 0

while (i < buffer.length) {
Expand Down
8 changes: 7 additions & 1 deletion src/scripts.js
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/scripts.json
Expand Up @@ -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": [
Expand Down

0 comments on commit c982622

Please sign in to comment.