[ 
https://issues.apache.org/jira/browse/FILEUPLOAD-338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17702803#comment-17702803
 ] 

Phu Dinh commented on FILEUPLOAD-338:
-------------------------------------

Hi,

This problem is still in commons-fileupload:1.5. 

I sent email reporting this bug to fileupload project at 
[[email protected]|mailto:[email protected]]

======

{color:#000000}To: [email protected] <[email protected]>{color}
{color:#000000}Subject: [fileupload] bug/regression - java.io.IOException: 
Failed to delete original file on Windows{color}

{color:#000000}Hi,{color}

{color:#000000}When uploading a file on Windows, IOException: Failed to delete 
original file is thrown.{color}

{color:#000000}This problem happens only on Windows OS when the uploading file 
is written to disk.{color}

{color:#000000}The DiskFileItem.write(File) is updated in commons-fileupload 
1.4.  It utilizes the org.apache.commons.io.FileUtils.moveFile() to copy and 
delete the .tmp file.{color}

[https://github.com/apache/commons-fileupload/blob/11a06cea605eadcba1d6ef125ff1448d6137ed7d/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java#L411]

{color:#000000}(commons-fileupload 1.5 has the similar call in addition to the 
remove of existing destination file; so I think it will have similar 
problem).{color}

{color:#000000}FileUtils.moveFile(File, File){color}

[https://github.com/apache/commons-io/blob/f22a4227401855ecbfdf8184bbe37275c3aeb5c3/src/main/java/org/apache/commons/io/FileUtils.java#L2392]

{color:#000000} if (!srcFile.delete())   can cause IOException on Windows when 
writing to disk.{color}

{color:#000000}To recreate the problem on Tomcat, I patched Tomcat 9.0.72 
DiskFileItem to use the commons.io FileUtils (also taking care of all its 
dependent classes) to show the exception:{color}

{color:#000000}======{color}
{color:#000000}27-Feb-2023 08:53:57.416 INFO [main] 
org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: 
[Apache Tomcat/9.0.72]{color}

{color:#000000}......{color}
{color:#000000}27-Feb-2023 08:54:00.391 INFO [main] 
org.apache.catalina.startup.Catalina.start Server startup in [3073] 
milliseconds{color}

{color:#000000}FileUploadWrite servlet, part.write(){color}

{color:#000000}DEBUG DiskFileItem copy from 1.4 source. write(){color}

{color:#000000}DEBUG DiskFileItem copy from 1.4 source. to DISK{color}

{color:#000000}DEBUG DiskFileItem copy from 1.4 source. FileUtils.moveFile, 
outputFile 
[C:\TomCat\output-Tomcat-9.72_Patch_1.4Fileupload\build\work\Catalina\localhost\TestFileUpload\upload_b107c4e1_4efe_454a_a9c3_f41186e63e6e_00000004.tmp]
 , file 
[C:\TomCat\output-Tomcat-9.72_Patch_1.4Fileupload\build\work\Catalina\localhost\TestFileUpload\FILEUPLOAD_writingfile.txt]{color}

{color:#000000}Exception writing file: java.io.IOException: 
java.io.IOException: Failed to delete original file 
'C:\TomCat\output-Tomcat-9.72_Patch_1.4Fileupload\build\work\Catalina\localhost\TestFileUpload\upload_b107c4e1_4efe_454a_a9c3_f41186e63e6e_00000004.tmp'
 after copy to 
'C:\TomCat\output-Tomcat-9.72_Patch_1.4Fileupload\build\work\Catalina\localhost\TestFileUpload\FILEUPLOAD_writingfile.txt'{color}
{color:#000000}======{color}

{color:#000000}My servlet app uses javax.servlet.http.Part.write(String) upload 
file to disk.{color}

{color:#000000}This is a regression from commons-fileupload 1.3.{color}

=======</end email>=====

 

Though the suggestion was to work with commons-io project, fileupload project 
was the one pulling in the defective IO codes.  Can you please at least 
revert/make a correct so fileupload can work on Windows?  I can file a separate 
report with commons-io project but don't know when it will be fixed.

 

Thank you!

> FileItem.write crash on Windows Tomcat
> --------------------------------------
>
>                 Key: FILEUPLOAD-338
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-338
>             Project: Commons FileUpload
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: yangshulin
>            Priority: Critical
>
> When I use FileItem.write on FileUpload 1.4, it will crash on Windows Tomcat, 
> linux server has not been tested. I find it is crashed by FileUtils.moveFile, 
> which reports IO Exception. FileUpload 1.3 works well, because it use file 
> streams copying.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to