From caf3f9140108f0a23643a6b538170d4b18490064 Mon Sep 17 00:00:00 2001 From: Diogo Resende Date: Tue, 27 Sep 2016 17:15:59 +0100 Subject: [PATCH] 0.4.8 - Adds a safety precaution that was added in 0.4.6 but was too greedy (#14) --- lib/Client/ReadStream.js | 3 ++- lib/Server/ReadStream.js | 3 ++- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) 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",