diff --git a/lib/Client/ReadStream.js b/lib/Client/ReadStream.js index e5b07f2..5329ab2 100644 --- a/lib/Client/ReadStream.js +++ b/lib/Client/ReadStream.js @@ -32,7 +32,8 @@ ReadStream.prototype._transform = function (chunk, encoding, next) { while (this.pending.length >= 6) { var pkg_len = this.pending.readUInt16BE(4) + 6; - if (this.pending.length < pkg_len) return next(); + if (this.pending.length < 8) return next(); // safety precaution + if (this.pending.length < pkg_len) return next(); // not all data yet var data = this.pending.slice(8, pkg_len); var pkg = { diff --git a/lib/Server/ReadStream.js b/lib/Server/ReadStream.js index 3c6ce77..104f106 100644 --- a/lib/Server/ReadStream.js +++ b/lib/Server/ReadStream.js @@ -32,7 +32,8 @@ ReadStream.prototype._transform = function (chunk, encoding, next) { while (this.pending.length >= 6) { var pkg_len = this.pending.readUInt16BE(4) + 6; - if (this.pending.length < pkg_len) return next(); + if (this.pending.length < 8) return next(); // safety precaution + if (this.pending.length < pkg_len) return next(); // not all data yet var data = this.pending.slice(8, pkg_len); var pkg = { diff --git a/package.json b/package.json index bdc6370..26d1da3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "modbus-tcp", - "version" : "0.4.7", + "version" : "0.4.8", "description" : "Modbus TCP/IP", "main" : "lib/Modbus.js", "repository" : "http://github.com/dresende/node-modbus-tcp.git",