This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new ab243584de Fix possible partial corrupted file copies
ab243584de is described below

commit ab243584de2ff7f4d1930af0a3743dcf67756acf
Author: remm <r...@apache.org>
AuthorDate: Fri Apr 28 15:19:42 2023 +0200

    Fix possible partial corrupted file copies
    
    PR#613 submitted by Jack Shirazi
---
 java/org/apache/catalina/startup/ExpandWar.java | 13 ++++++++++++-
 webapps/docs/changelog.xml                      |  5 +++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/catalina/startup/ExpandWar.java 
b/java/org/apache/catalina/startup/ExpandWar.java
index b2f6e58895..4d7cf78e85 100644
--- a/java/org/apache/catalina/startup/ExpandWar.java
+++ b/java/org/apache/catalina/startup/ExpandWar.java
@@ -17,6 +17,7 @@
 package org.apache.catalina.startup;
 
 import java.io.BufferedOutputStream;
+import java.io.EOFException;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -268,7 +269,17 @@ public class ExpandWar {
             } else {
                 try (FileChannel ic = (new 
FileInputStream(fileSrc)).getChannel();
                         FileChannel oc = (new 
FileOutputStream(fileDest)).getChannel()) {
-                    ic.transferTo(0, ic.size(), oc);
+                    long size = ic.size();
+                    long position = 0;
+                    while (size > 0) {
+                        long count = ic.transferTo(position, size, oc);
+                        if (count > 0) {
+                            position += count;
+                            size -= count;
+                        } else {
+                            throw new EOFException();
+                        }
+                    }
                 } catch (IOException e) {
                     log.error(sm.getString("expandWar.copy", fileSrc, 
fileDest), e);
                     result = false;
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 6aaabb42c6..c0b9389f53 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -129,6 +129,11 @@
         like for headers and attributes. Those will be logged as sub objects.
         (rjung)
       </update>
+      <fix>
+        <pr>613</pr>: Fix possible partial corrupted file copies when using
+        file lockig protection or the manager servlet. Submitted
+        by Jack Shirazi. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to