File tree 1 file changed +7
-1
lines changed
1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ function IncomingForm(opts) {
25
25
26
26
this . maxFields = opts . maxFields || 1000 ;
27
27
this . maxFieldsSize = opts . maxFieldsSize || 2 * 1024 * 1024 ;
28
+ this . maxFileSize = opts . maxFileSize || 2 * 1024 * 1024 ;
28
29
this . keepExtensions = opts . keepExtensions || false ;
29
30
this . uploadDir = opts . uploadDir || ( os . tmpdir && os . tmpdir ( ) ) || os . tmpDir ( ) ;
30
31
this . encoding = opts . encoding || 'utf-8' ;
@@ -39,6 +40,7 @@ function IncomingForm(opts) {
39
40
this . _parser = null ;
40
41
this . _flushing = 0 ;
41
42
this . _fieldsSize = 0 ;
43
+ this . _fileSize = 0 ;
42
44
this . openedFiles = [ ] ;
43
45
44
46
return this ;
@@ -214,6 +216,11 @@ IncomingForm.prototype.handlePart = function(part) {
214
216
this . openedFiles . push ( file ) ;
215
217
216
218
part . on ( 'data' , function ( buffer ) {
219
+ self . _fileSize += buffer . length ;
220
+ if ( self . _fileSize > self . maxFileSize ) {
221
+ self . _error ( new Error ( 'maxFileSize exceeded, received ' + self . _fileSize + ' bytes of file data' ) ) ;
222
+ return ;
223
+ }
217
224
if ( buffer . length == 0 ) {
218
225
return ;
219
226
}
@@ -552,4 +559,3 @@ IncomingForm.prototype._maybeEnd = function() {
552
559
553
560
this . emit ( 'end' ) ;
554
561
} ;
555
-
You can’t perform that action at this time.
0 commit comments