Skip to content

Commit

Permalink
2.0.1: Updated string underflow detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan7g committed Jan 21, 2019
1 parent 9419c6b commit 372b692
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/types/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ module.exports = {
'parse': (buf, from, data) => {
const stringLengthLength = 4

if (buf.length - from < stringLengthLength) {
return {
'hadUnderflow': true
}
}

const stringLength = buf.readUIntLE(from, stringLengthLength)
const stringStart = from + stringLengthLength

if (buf.length - from < stringLength + stringLengthLength) {
return {
'hadUnderflow': true
}
}

return {
'readBytes': stringLengthLength + stringLength,
'data': buf.toString(data.encoding, stringStart, stringStart + stringLength),
'hadUnderflow': buf.length - from < stringLength + stringLengthLength
'hadUnderflow': false
}
},
'serialize': (value, data) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "protocore",
"version": "2.0.0",
"version": "2.0.1",
"description": "Specify and deploy custom binary protocol structures in Node",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 372b692

Please sign in to comment.