Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload size validation for each file #423

Merged
merged 3 commits into from
Mar 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void upload(@Observes ControllerMethodDiscovered event, MutableRequest re

ServletFileUpload uploader = createServletFileUpload(config);
uploader.setSizeMax(config.getSizeLimit());
uploader.setFileSizeMax(config.getFileSizeLimit());

try {
final List<FileItem> items = uploader.parseRequest(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public long getSizeLimit() {
return 2 * 1024 * 1024;
}

@Override
public long getFileSizeLimit() {
return 2 * 1024 * 1024;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may we can grow this value to Long.MAX_VALUE and allow app to define lower values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of a security problem. If we leave this unlimited, someone can start 10 uploads with 2Gb and break the server.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok then

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Lucas! It's better to leave as it is!

On Wed, Mar 5, 2014 at 11:38 AM, Lucas Cavalcanti
notifications@gitpro.ttaallkk.topwrote:

In
vraptor-core/src/main/java/br/com/caelum/vraptor/observer/upload/DefaultMultipartConfig.java:

@@ -50,6 +50,11 @@ public long getSizeLimit() {
}

@Override
  • public long getFileSizeLimit() {
  •   return 2 \* 1024 \* 1024;
    

It's kind of a security problem. If we leave this unlimited, someone can
start 10 uploads with 2Gb and break the server.

Reply to this email directly or view it on GitHubhttps://github.com//pull/423/files#r10301148
.

Rafael Ponte
http://cursos.triadworks.com.br

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I merge the original pull request?

}

@Override
public File getDirectory() {
if (tmpdir == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public interface MultipartConfig {
*/
long getSizeLimit();

/**
* The max size of each uploaded file (in bytes).
*
* @return
*/
long getFileSizeLimit();

/**
* Gets the temporary directory.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void doNothingWhenFileUploadExceptionOccurs() throws Exception {
@Test
public void shouldValidateWhenSizeLimitExceededExceptionOccurs() throws Exception {
when(observer.createServletFileUpload(config)).thenReturn(servletFileUpload);
when(servletFileUpload.parseRequest(request)).thenThrow(new FileUploadBase.SizeLimitExceededException("", 0L, 0L));
when(servletFileUpload.parseRequest(request)).thenThrow(new FileUploadBase.SizeLimitExceededException("", 1L, 2L));

observer.upload(event, request, config, validator);

Expand Down