@@ -316,4 +316,44 @@ function (ServerRequestInterface $request) {
316316 $ this ->assertTrue (isset ($ body ['a ' ]));
317317 $ this ->assertCount ($ allowed , $ body ['a ' ]);
318318 }
319+
320+ public function testMultipartFormDataTruncatesExcessiveNumberOfEmptyFileUploads ()
321+ {
322+ // ini setting exists in PHP 5.3.9, not in HHVM: https://3v4l.org/VF6oV
323+ // otherwise default to 1000 as implemented within
324+ $ allowed = (int )ini_get ('max_input_vars ' );
325+ if ($ allowed === 0 ) {
326+ $ allowed = 1000 ;
327+ }
328+
329+ $ middleware = new RequestBodyParserMiddleware ();
330+
331+ $ boundary = "---------------------------12758086162038677464950549563 " ;
332+
333+ $ data = "" ;
334+ for ($ i = 0 ; $ i < $ allowed + 1 ; ++$ i ) {
335+ $ data .= "-- $ boundary \r\n" ;
336+ $ data .= "Content-Disposition: form-data; name= \"empty[] \"; filename= \"\"\r\n" ;
337+ $ data .= "\r\n" ;
338+ $ data .= "\r\n" ;
339+ }
340+ $ data .= "-- $ boundary-- \r\n" ;
341+
342+ $ request = new ServerRequest ('POST ' , 'http://example.com/ ' , array (
343+ 'Content-Type ' => 'multipart/form-data; boundary= ' . $ boundary ,
344+ ), $ data , 1.1 );
345+
346+ /** @var ServerRequestInterface $parsedRequest */
347+ $ parsedRequest = $ middleware (
348+ $ request ,
349+ function (ServerRequestInterface $ request ) {
350+ return $ request ;
351+ }
352+ );
353+
354+ $ body = $ parsedRequest ->getUploadedFiles ();
355+ $ this ->assertCount (1 , $ body );
356+ $ this ->assertTrue (isset ($ body ['empty ' ]));
357+ $ this ->assertCount ($ allowed , $ body ['empty ' ]);
358+ }
319359}
0 commit comments