简体   繁体   中英

java.io.IOException when posting multipart/form-data from Firefox 74 / 75 and using Apache AJP connector on server side

Since version 74 of Firefox, file sent using "multipart/form-data" form with file size above about 1.8 MB are raising error.

Note: file sent using AJAX are working fine. Only multipart form submit cause the issue.

HTML code:

<form name="formUpload" action="AdminImportInssAseg" method="POST"
            enctype="multipart/form-data" onsubmit="return validate_form(this);">
    <table class="centrado green">
        <tr>
            <td><input type="File" name="miadjuntoSolvenciaX" class="mdt">&nbsp;
            </td>
        </tr>
        <tr>
            <td align="center" colspan="2"><a href="#"
                onClick="if(validate_form(formUpload)) formUpload.submit();"
                title="Importar el archivo"><img alt='' border="0"
                    src="./images/add.gif" height="30"></a></td>
        </tr>
    </table>
</form>

Java code:

            FileItemIterator iter = upload.getItemIterator(request);
            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                if (item.isFormField()) {
                    continue;
                } else {
                        filename = item.getName();
                        contentType = item.getContentType();
                        String inputLine;
                        InputStream fis = item.openStream();
                        BufferedReader in = null;
                        in = new BufferedReader(new InputStreamReader(fis,"ISO-8859-1"));
                        while ((inputLine = in.readLine()) != null) {
                            try{
                                out.println("*"+inputLine+"*<br>");
                            }
                            catch (Exception e){
                                out.println("<p>Error: <b>"+e.getMessage() + "</b></p>");
                            }
                        }
                        fis.close();
                }
            }

I can see it reads the file, but fails in the middle of it when using Firefox 74+.

Error stack trace can be found below this message.

When using Firefox 73 or lower everything works fine.

When connecting directly to Tomcat port (not using AJP connector), everything works fine (inlcuding with Firefox 74/75).

Code has been used for more than a decade. Java coding, Apache and Tomcat have not been modified recently.

Server version: Apache/2.4.43 (Linux/SUSE)

I noticed that the "temporary" file saved is always cut at 188416 bytes (while the uploaded file is actually bigger).

csimon@linux-069t:/tomcat/temp> l
total 376
drwxr-xr-x 2 csimon users   4096 may  1 10:53 ./
drwxr-xr-x 9 csimon users   4096 ago 29  2018 ../
-rw-r--r-- 1 csimon users 188416 may  1 10:45 EMP59_AF_GA_202005011.CSV
-rw-r--r-- 1 csimon users 188416 may  1 10:37 EMP59_AF_GA_20200501.CSV

Issue was reported by a production user, but I could reproduce it locally.

Only the use of Firefox 74 and 75 causes the problem (I tested with Firefox 71 -> 75), so it must be linked to some change in Firefox (Linux and Windows versions at least). I could not find explanation looking at Firefox release notes. Anyone getting ideas of what could cause this and how this can be fixed.

I have already had Firefox upgrade related issues in the past, usually fixed changing some values in Firefox config via "about:config". The trick is finding the right parameter to update...

Error log from AJP connector log when using Firefo 74+:

[Sat May 02 18:27:55.801 2020] [15619:139986498496512] [info] init_jk::mod_jk.c (3591): mod_jk/1.2.46 initialized
[Sat May 02 18:27:55.805 2020] [15619:139986498496512] [info] init_jk::mod_jk.c (3591): mod_jk/1.2.46 initialized
[Sat May 02 18:28:02.669 2020] [15641:139986189342464] [info] ajp_process_callback::jk_ajp_common.c (2074): (ajp13) Writing to client aborted or client network problems
[Sat May 02 18:28:02.669 2020] [15641:139986189342464] [info] ajp_service::jk_ajp_common.c (2775): (ajp13) sending request to tomcat failed (unrecoverable), because of client write error (attempt=1)
[Sat May 02 18:28:02.670 2020] [15641:139986189342464] [info] jk_handler::mod_jk.c (2984): Aborting connection for worker=ajp13
[Sat May 02 18:28:15.289 2020] [15641:139986189342464] [info] ajp_read_into_msg_buff::jk_ajp_common.c (1550): (ajp13) receiving data from client failed. Connection aborted or network problems
[Sat May 02 18:28:15.289 2020] [15641:139986189342464] [info] ajp_process_callback::jk_ajp_common.c (2102): (ajp13) Reading from client aborted or client network problems
[Sat May 02 18:28:15.289 2020] [15641:139986189342464] [info] ajp_service::jk_ajp_common.c (2775): (ajp13) sending request to tomcat failed (unrecoverable), because of client read error (attempt=1)
[Sat May 02 18:28:15.310 2020] [15641:139986189342464] [info] jk_handler::mod_jk.c (2984): Aborting connection for worker=ajp13

Tomcat error stack trace when using Firefox 74+:

java.io.IOException: Fallo en lectura de Conector
    at org.apache.coyote.ajp.AjpProcessor.read(AjpProcessor.java:313)
    at org.apache.coyote.ajp.AjpProcessor.readMessage(AjpProcessor.java:364)
    at org.apache.coyote.ajp.AjpProcessor.receive(AjpProcessor.java:331)
    at org.apache.coyote.ajp.AbstractAjpProcessor.refillReadBuffer(AbstractAjpProcessor.java:662)
    at org.apache.coyote.ajp.AbstractAjpProcessor$SocketInputBuffer.doRead(AbstractAjpProcessor.java:1140)
    at org.apache.coyote.Request.doRead(Request.java:422)
    at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:290)
    at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:449)
    at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:315)
    at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:200)
    at com.oreilly.servlet.multipart.BufferedServletInputStream.fill(BufferedServletInputStream.java:64)
    at com.oreilly.servlet.multipart.BufferedServletInputStream.readLine(BufferedServletInputStream.java:108)
    at com.oreilly.servlet.multipart.LimitedServletInputStream.readLine(LimitedServletInputStream.java:60)
    at com.oreilly.servlet.multipart.PartInputStream.fill(PartInputStream.java:97)
    at com.oreilly.servlet.multipart.PartInputStream.read(PartInputStream.java:195)
    at com.oreilly.servlet.multipart.PartInputStream.read(PartInputStream.java:156)
    at com.oreilly.servlet.multipart.FilePart.write(FilePart.java:208)
    at com.oreilly.servlet.multipart.FilePart.writeTo(FilePart.java:167)
    at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:271)
    at servlet.presentacion.admin.AdminImportInssAseg.doPost(AdminImportInssAseg.java:101)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:193)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

Header Firefox version 72: 在此处输入图像描述

Header Firefox version 75: 在此处输入图像描述

Was failing using com.oreilly.servlet.MultipartRequest. Was failing using org.apache.commons.fileupload.

Got it working using Java Servlet Technology and setting maxFileSize higher (default is 2MB).

I can't understand why it works with old versions of Firefox and not with new ones... but my problem is solved.

@WebServlet("/AdminImportInssAseg")
@MultipartConfig (fileSizeThreshold=1024*1024*10,   // 1 MB 
     maxFileSize=1024*1024*50,          // 50 MB
     maxRequestSize=1024*1024*100)      // 100 MB
public class AdminImportInssAseg extends HttpServlet {

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException,
        IOException {
        Part filePart = request.getPart("miadjuntoSolvenciaX"); // Retrieves <input type="file" name="file">
        filename = filePart.getName();
        fileSize = filePart.getSize();
        contentType = filePart.getContentType();
        InputStream fis = filePart.getInputStream();
        BufferedReader in = null;
        in = new BufferedReader(new InputStreamReader(fis,"ISO-8859-1"));
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
        ...
        }           
        fis.close();
        filePart.delete();
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM