From df1b73083aaed459eef1da609956e5200dd5f7f2 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Sat, 11 Jan 2020 15:04:26 +0200 Subject: [PATCH] fixed exception with invalid buffer length --- imap-core/lib/length-limiter.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/imap-core/lib/length-limiter.js b/imap-core/lib/length-limiter.js index 8569f0c2..1bf96f2c 100644 --- a/imap-core/lib/length-limiter.js +++ b/imap-core/lib/length-limiter.js @@ -63,8 +63,10 @@ class LengthLimiter extends Transform { _flush(done) { if (!this.finished) { // add padding if incoming stream stopped too early - let buf = Buffer.from(this.padding.repeat(this.expectedLength - this.byteCounter)); - this.push(buf); + if (this.expectedLength > this.byteCounter) { + let buf = Buffer.from(this.padding.repeat(this.expectedLength - this.byteCounter)); + this.push(buf); + } this.finished = true; } done();