This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new 31d8b454f8 Fix possible partial corrupted file copies
31d8b454f8 is described below
commit 31d8b454f83d8017edda1b87c6d33d9c7aa29f00
Author: remm <[email protected]>
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 2d0b377bd8..20c92061e5 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 35c48e5a68..48dd526b27 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: [email protected]
For additional commands, e-mail: [email protected]