From 954ab41e0e670f2033ff571dd47a8c0eae5da848 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 31 Oct 2016 01:53:24 +0000 Subject: [PATCH] Reject invalid signature lengths for fromRpcSig --- index.js | 4 ++++ test/index.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/index.js b/index.js index 9deec8ff..e38967d5 100644 --- a/index.js +++ b/index.js @@ -431,6 +431,10 @@ exports.toRpcSig = function (v, r, s) { exports.fromRpcSig = function (sig) { sig = exports.toBuffer(sig) + if (sig.length !== 65) { + throw new Error('Invalid signature length') + } + var v = sig[64] // support both versions of `eth_sign` responses if (v < 27) { diff --git a/test/index.js b/test/index.js index b9811590..873e3c82 100644 --- a/test/index.js +++ b/test/index.js @@ -535,4 +535,13 @@ describe('message sig', function () { s: s }) }) + + it('should throw on invalid length', function () { + assert.throws(function () { + ethUtils.fromRpcSig('') + }) + assert.throws(function () { + ethUtils.fromRpcSig('0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca660042') + }) + }) })