Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
Reject invalid signature lengths for fromRpcSig
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Oct 31, 2016
1 parent 6afa374 commit 954ab41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions test/index.js
Expand Up @@ -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')
})
})
})

0 comments on commit 954ab41

Please sign in to comment.