From 4e6edcf1ba03a85de10f367c90b4f1f31d198628 Mon Sep 17 00:00:00 2001 From: Xaxatix Date: Wed, 21 Oct 2015 10:27:08 +0300 Subject: [PATCH 1/2] Added max upload size --- lib/incoming_form.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/incoming_form.js b/lib/incoming_form.js index e3c8019a..fdd5be8f 100644 --- a/lib/incoming_form.js +++ b/lib/incoming_form.js @@ -25,6 +25,7 @@ function IncomingForm(opts) { this.maxFields = opts.maxFields || 1000; this.maxFieldsSize = opts.maxFieldsSize || 2 * 1024 * 1024; + this.maxFileSize = opts.maxFileSize || 2 * 1024 * 1024; this.keepExtensions = opts.keepExtensions || false; this.uploadDir = opts.uploadDir || os.tmpDir(); this.encoding = opts.encoding || 'utf-8'; @@ -39,6 +40,7 @@ function IncomingForm(opts) { this._parser = null; this._flushing = 0; this._fieldsSize = 0; + this._fileSize = 0; this.openedFiles = []; return this; @@ -214,6 +216,11 @@ IncomingForm.prototype.handlePart = function(part) { this.openedFiles.push(file); part.on('data', function(buffer) { + self._fileSize += buffer.length; + if (self._fileSize > maxFileSize) { + self._error(new Error('maxFileSize exceeded, received '+self._fileSize+' bytes of file data')); + return; + } if (buffer.length == 0) { return; } @@ -555,4 +562,3 @@ IncomingForm.prototype._maybeEnd = function() { this.emit('end'); }; - From 4cd11b3658125ae340201a28dec4ae61fa576490 Mon Sep 17 00:00:00 2001 From: Xaxatix Date: Wed, 21 Oct 2015 10:31:24 +0300 Subject: [PATCH 2/2] Self reference for size fix --- lib/incoming_form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/incoming_form.js b/lib/incoming_form.js index fdd5be8f..ee512962 100644 --- a/lib/incoming_form.js +++ b/lib/incoming_form.js @@ -217,7 +217,7 @@ IncomingForm.prototype.handlePart = function(part) { part.on('data', function(buffer) { self._fileSize += buffer.length; - if (self._fileSize > maxFileSize) { + if (self._fileSize > self.maxFileSize) { self._error(new Error('maxFileSize exceeded, received '+self._fileSize+' bytes of file data')); return; }