[
https://issues.apache.org/jira/browse/WW-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17433014#comment-17433014
]
KON-SUN-TACK edited comment on WW-5088 at 10/22/21, 2:35 PM:
-------------------------------------------------------------
In org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest:
{code:java}
protected DiskFileItemFactory createDiskFileItemFactory(String saveDir) {
DiskFileItemFactory fac = new DiskFileItemFactory();
// Make sure that the data is written to file
fac.setSizeThreshold(0);
if (saveDir != null) {
fac.setRepository(new File(saveDir));
}
return fac;
}
{code}
For an empty file, seeing org.apache.commons.io.output.ThresholdingOutputStream
checking threshold with an "greater than" operator (>),
I guess "fac.setSizeThreshold(0);" does not actually make sure the data is
written to a file.
(hence getting null storeLocation)
was (Author: jeanjean):
In org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest:
{{protected DiskFileItemFactory createDiskFileItemFactory(String saveDir) {}}
{{ DiskFileItemFactory fac = new DiskFileItemFactory();}}
{{ // Make sure that the data is written to file}}
{{ fac.setSizeThreshold(0);}}
{{ if (saveDir != null) {}}
{{ fac.setRepository(new File(saveDir));}}
{{ }}}
{{ return fac;}}
{{ }}}
For an empty file, seeing org.apache.commons.io.output.ThresholdingOutputStream
checking threshold with an "greater than" operator (>),
I guess "fac.setSizeThreshold(0);" does not actually make sure the data is
written to a file.
> Empty file upload gives wrong error message
> -------------------------------------------
>
> Key: WW-5088
> URL: https://issues.apache.org/jira/browse/WW-5088
> Project: Struts 2
> Issue Type: Bug
> Components: Core Interceptors
> Affects Versions: 2.5.22
> Reporter: Greg Huber
> Priority: Minor
> Fix For: 2.6
>
> Time Spent: 2h
> Remaining Estimate: 0h
>
> On an empty file upload the storeLocation is null, so adds a file new
> StrutsUploadedFile(null)
> JakartaMultiPartRequest
> {code:java}
> List fileList = new ArrayList<>(items.size());
> for (FileItem fileItem : items) {
> File storeLocation = ((DiskFileItem) fileItem).getStoreLocation();
> if (fileItem.isInMemory() && storeLocation != null &&
> !storeLocation.exists()) {
> try {
> storeLocation.createNewFile();
> } catch (IOException e) {
> LOG.error("Cannot write uploaded empty file to disk: {}",
> storeLocation.getAbsolutePath(), e);
> }
> }
> fileList.add(new StrutsUploadedFile(storeLocation));
> }
> {code}
> The FileUploadInterceptor checks for a null file but not null content from
> the new StrutsUploadedFile(null).
> eg for an empty file main.js
> Error message should be:
> Error uploading: main.js
> but gives:
> Error setting expression 'uploadedFiles' with value
> ['org.apache.struts2.dispatcher.multipart.StrutsUploadedFile@202585bc', ]
> Error setting expression 'uploadedFiles' with value
> ['org.apache.struts2.dispatcher.multipart.StrutsUploadedFile@49553150', ]
--
This message was sent by Atlassian Jira
(v8.3.4#803005)