Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-19045

FileSizeLimitException swallowed in file upload

    Details

      Description

      I have encounteredan error while uploading a file in my web content edit pane.

      1. I have created a new web content structure in which I have placed an image field.
      2. I have set a limit in my portal-ext.properties: com.liferay.portal.upload.UploadServletRequestImpl.max.size=102400

      My Test case

      1. I create a new web content without the image.
      2. I publish the webcontent.
      3. I edit the webcontent
      4. I add a file that has a size larger than 100k,
      5. I press the publish button

      Result:
      The page is forwarded to "New Web Content" page

      Expected:
      What I would expect is to stay on the edit page and have an error specifying that the file size is larger that the maximum size.

      Log file
      In the log files, I see that an exception is thrown
      14:20:49,931 ERROR [UploadServletRequestImpl:101] org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (214181) exceeds the configured maximum (102400)
      org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (214181) exceeds the configured maximum (102400)
      	at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:914)
      	at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
      	at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:349)
      	at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
      	at com.liferay.portal.upload.LiferayFileUpload.parseRequest(LiferayFileUpload.java:56)
      	at com.liferay.portal.upload.UploadServletRequestImpl.<init>(UploadServletRequestImpl.java:72)
              ...
      

      I then looked at the code for the UploadServletRequestImpl, and in there we can see that the exception is swallowed and no information is raised to the calling application.

      com.liferay.portal.upload.UploadServletRequestImpl.java
      	public UploadServletRequestImpl(HttpServletRequest request) {
      		super(request);
      
      		_params = new LinkedHashMap<String, LiferayFileItem[]>();
      
      		try {
      			ServletFileUpload servletFileUpload = new LiferayFileUpload(
      				new LiferayFileItemFactory(DEFAULT_TEMP_DIR), request);
      
      			servletFileUpload.setSizeMax(DEFAULT_SIZE_MAX);
      
      			_lsr = new LiferayServletRequest(request);
      
      			List<LiferayFileItem> list = servletFileUpload.parseRequest(_lsr);
      
      			for (LiferayFileItem fileItem : list) {
      				if (fileItem.isFormField()) {
      					fileItem.setString(request.getCharacterEncoding());
      				}
      
      				LiferayFileItem[] fileItems = _params.get(
      					fileItem.getFieldName());
      
      				if (fileItems == null) {
      					fileItems = new LiferayFileItem[] {fileItem};
      				}
      				else {
      					LiferayFileItem[] newFileItems =
      						new LiferayFileItem[fileItems.length + 1];
      
      					System.arraycopy(
      						fileItems, 0, newFileItems, 0, fileItems.length);
      
      					newFileItems[newFileItems.length - 1] = fileItem;
      
      					fileItems = newFileItems;
      				}
      
      				_params.put(fileItem.getFieldName(), fileItems);
      			}
      		}
      		catch (FileUploadException fue) {
      			_log.error(fue, fue);
      		}
      	}
      
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              pani.gui Pani Gui (Inactive)
              Reporter:
              benoitgoyette Benoit Goyette (Inactive)
              Participants of an Issue:
              Recent user:
              Marta Elicegui
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                8 years, 31 weeks, 4 days ago

                  Packages

                  Version Package
                  6.0.X EE
                  --Sprint 12/11
                  6.1.0 CE RC1