Alex Rivera | Logout

Uploading to Blobstore gives a Java heap OutOfMemoryError

Asked 2010-07-05T03:18:28.297
14

I'm doing a very simple upload form to my Google App Engine application. In the client GWT code I have something like:

final FormPanel uploadForm = new FormPanel();
uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
uploadForm.setMethod(FormPanel.METHOD_POST);

uploadBtn.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            blobstoreUploadURLService.getBlobstoreUploadURL("/banzai/process-pdf", new AsyncCallback<String>() {

                @Override
                public void onFailure(Throwable caught) {
                    // TODO Auto-generated method stub
                    System.err.println("FAILURE DURING UPLOAD SERVICE");
                }

                @Override
                public void onSuccess(String result) {
                    uploadForm.setAction(result);
                    uploadForm.submit();
                }

            });
        }
    });

And it uses a new FileUpload() to select the file. When I test it, either locally or on a deployed instance, I get the following error in the logs:

WARNING: Error for /_ah/upload/agdrYnNrYWFychsLEhVfX0Jsb2JVcGxvYWRTZXNzaW9uX18YAww java.lang.OutOfMemoryError: Java heap space
  at java.util.Arrays.copyOf(Arrays.java:2786)
  at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:71)
  at javax.mail.internet.MimeMultipart.readTillFirstBoundary(MimeMultipart.java:316)
  at javax.mail.internet.MimeMultipart.parse(MimeMultipart.java:186)
  at javax.mail.internet.MimeMultipart.getCount(MimeMultipart.java:109)
  at com.google.appengine.api.blobstore.dev.UploadBlobServlet.handleUpload(UploadBlobServlet.java:135)
  at com.google.appengine.api.blobstore.dev.UploadBlobServlet.access$000(UploadBlobServlet.java:72)
  at com.google.appengine.api.blobstore.dev.UploadBlobServlet$1.run(UploadBlobServlet.java:100)
  at java.security.AccessController.doPrivileged(Native Metho
Edit
Report

1 Answer

16

Okay, so the incredibly silly problem turned out to be that I had left out a "name" attribute on the FileInput element of the form. This evidently makes the resulting stream unparseable, which causes the MimeMultipart parser to run out of memory.

Even though the problem ended up being mine, and was easily fixable, I still consider this a bug in AppEngine because there's no way such a simple mistake should cause an OutOfMemoryError and crash; this could also be a source of DOS vulnerabilities just by crafting malicious HTTP requests. I'll file a bug report with Google.

answered 2010-07-06T19:34:05.087

Your Answer