Bug 32023 - CGIServlet fails to handle post message with multipart/form data
CGIServlet fails to handle post message with multipart/form data
Status: RESOLVED FIXED
Product: Tomcat 5
Classification: Unclassified
Component: Servlets:CGI
5.0.0
Other Windows XP
: P3 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
: 32028 (view as bug list)
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2004-11-02 15:46 UTC by Antti Granqvist
Modified: 2004-11-19 06:51 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Antti Granqvist 2004-11-02 15:46:47 UTC
Following error message appears in the log.
INFO: cgi: runCGI (stderr):CGI.pm: Server closed socket during multipart read 
(client aborted?).

The problem is that when creating the inputstream for cgi component there is 
only one single 'read' on the ServletInputStream, in reasonably large uploads 
this will not drain the buffer.

I have a pathch ready and it looks like this:

diff -u -r1.27 CGIServlet.java
--- CGIServlet.java	14 Oct 2004 08:14:47 -0000	1.27
+++ CGIServlet.java	2 Nov 2004 15:42:25 -0000
@@ -1691,7 +1691,12 @@
             ByteArrayOutputStream contentStream = null;
             if(!"".equals(sContentLength)) {
                 byte[] content = new byte[Integer.parseInt(sContentLength)];
-                int lenRead = stdin.read(content);
+                int lenRead = 0;
+                do {
+                    int partRead = stdin.read(
+                        content,lenRead,content.length-lenRead);
+                    lenRead += partRead;
+                } while (lenRead > 0 && lenRead < content.length);
                 contentStream = new ByteArrayOutputStream(
                         Integer.parseInt(sContentLength));
                 if ("POST".equals(env.get("REQUEST_METHOD"))) {

Hope someone can commit it to cvs repository.

Maybe there should be an initial parameter for the servlet also that restricts 
maximum size of the upload?


--
Antti
Comment 1 Yoav Shapira 2004-11-03 15:20:17 UTC
*** Bug 32028 has been marked as a duplicate of this bug. ***
Comment 2 Yoav Shapira 2004-11-19 15:44:47 UTC
Done for Tomcat 5.5.5.
Comment 3 Yoav Shapira 2004-11-19 15:51:24 UTC
And for 5.0.30.