bufferutils/script: allow for invalid pushDatInts, fixes #367

This commit is contained in:
Daniel Cousens 2015-03-04 20:48:28 +11:00
parent 2f100e0eae
commit ec66ca9b1a
2 changed files with 7 additions and 1 deletions

View file

@ -27,16 +27,19 @@ function readPushDataInt (buffer, offset) {
// 8 bit // 8 bit
} else if (opcode === opcodes.OP_PUSHDATA1) { } else if (opcode === opcodes.OP_PUSHDATA1) {
if (offset + 2 > buffer.length) return null
number = buffer.readUInt8(offset + 1) number = buffer.readUInt8(offset + 1)
size = 2 size = 2
// 16 bit // 16 bit
} else if (opcode === opcodes.OP_PUSHDATA2) { } else if (opcode === opcodes.OP_PUSHDATA2) {
if (offset + 3 > buffer.length) return null
number = buffer.readUInt16LE(offset + 1) number = buffer.readUInt16LE(offset + 1)
size = 3 size = 3
// 32 bit // 32 bit
} else { } else {
if (offset + 5 > buffer.length) return null
assert.equal(opcode, opcodes.OP_PUSHDATA4, 'Unexpected opcode') assert.equal(opcode, opcodes.OP_PUSHDATA4, 'Unexpected opcode')
number = buffer.readUInt32LE(offset + 1) number = buffer.readUInt32LE(offset + 1)

View file

@ -38,8 +38,11 @@ Script.fromBuffer = function (buffer) {
// data chunk // data chunk
if ((opcode > opcodes.OP_0) && (opcode <= opcodes.OP_PUSHDATA4)) { if ((opcode > opcodes.OP_0) && (opcode <= opcodes.OP_PUSHDATA4)) {
var d = bufferutils.readPushDataInt(buffer, i) var d = bufferutils.readPushDataInt(buffer, i)
i += d.size
// did reading a pushDataInt fail? return non-chunked script
if (d === null) return new Script(buffer, [])
i += d.size
var data = buffer.slice(i, i + d.number) var data = buffer.slice(i, i + d.number)
i += d.number i += d.number