Skip to content
Snippets Groups Projects
Commit 58929438 authored by James Calfee's avatar James Calfee
Browse files

Add fail-safe to memo decryption in case sender does not length prefix the memo. #202

parent 8f84aced
No related branches found
No related tags found
No related merge requests found
...@@ -33,18 +33,10 @@ export function decode(private_key, memo) { ...@@ -33,18 +33,10 @@ export function decode(private_key, memo) {
const mbuf = ByteBuffer.fromBinary(memo.toString('binary'), ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN) const mbuf = ByteBuffer.fromBinary(memo.toString('binary'), ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN)
try { try {
mbuf.mark() mbuf.mark()
// I get better luck using readVString .. but (see cache)
return mbuf.readVString() return mbuf.readVString()
} catch(e) { } catch(e) {
// Piston's encrypted memos fail the above varibale length utf-8 conversion.
// The origainal code works for Piston.
// https://github.com/steemit/steemit.com/issues/202
mbuf.reset() mbuf.reset()
const len = mbuf.readVarint32() // remove the varint length prefix // Sender did not length-prefix the memo
const remaining = mbuf.remaining()
if(len !== remaining) // warn
console.error(`Memo's length prefix ${len} does not match remaining bytes ${remaining}`)
memo = new Buffer(mbuf.toString('binary'), 'binary').toString('utf-8') memo = new Buffer(mbuf.toString('binary'), 'binary').toString('utf-8')
return memo return memo
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment