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

markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 70d0d45404 Align getContent() behaviour
70d0d45404 is described below

commit 70d0d45404d80c5eaf682dc2c947dabb0fc167d1
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Jul 22 11:31:02 2026 +0100

    Align getContent() behaviour
---
 java/org/apache/catalina/webresources/AbstractArchiveResource.java  | 6 ++++--
 .../catalina/webresources/AbstractSingleArchiveResourceSet.java     | 2 +-
 java/org/apache/catalina/webresources/FileResource.java             | 6 +++++-
 java/org/apache/catalina/webresources/LocalStrings.properties       | 3 ++-
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/catalina/webresources/AbstractArchiveResource.java 
b/java/org/apache/catalina/webresources/AbstractArchiveResource.java
index f206d6e1d6..408f42abe4 100644
--- a/java/org/apache/catalina/webresources/AbstractArchiveResource.java
+++ b/java/org/apache/catalina/webresources/AbstractArchiveResource.java
@@ -219,8 +219,10 @@ public abstract class AbstractArchiveResource extends 
AbstractResource {
 
         if (len > Integer.MAX_VALUE) {
             // Can't create an array that big
-            throw new IllegalStateException(
-                    sm.getString("abstractResource.getContentTooLarge", 
getWebappPath(), Long.valueOf(len)));
+            if (getLog().isDebugEnabled()) {
+                
getLog().debug(sm.getString("abstractResource.getContentTooLarge", 
getWebappPath(), Long.valueOf(len)));
+            }
+            return null;
         }
 
         if (len < 0) {
diff --git 
a/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java 
b/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
index 2e1764a12c..2040740b63 100644
--- 
a/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
+++ 
b/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
@@ -65,7 +65,7 @@ public abstract class AbstractSingleArchiveResourceSet 
extends AbstractArchiveRe
             try {
                 start();
             } catch (LifecycleException e) {
-                throw new 
IllegalStateException(sm.getString("abstractArchiveResourceSet.startFail"), e);
+                throw new 
IllegalStateException(sm.getString("abstractSingleArchiveResourceSet.startFail"),
 e);
             }
         }
     }
diff --git a/java/org/apache/catalina/webresources/FileResource.java 
b/java/org/apache/catalina/webresources/FileResource.java
index e18255ce31..ba33a68054 100644
--- a/java/org/apache/catalina/webresources/FileResource.java
+++ b/java/org/apache/catalina/webresources/FileResource.java
@@ -260,6 +260,10 @@ public class FileResource extends AbstractResource {
                 }
                 pos += n;
             }
+            if (pos < size) {
+                // Stream ended before expected size — return null to avoid 
partial data
+                return null;
+            }
         } catch (IOException ioe) {
             if (getLog().isDebugEnabled()) {
                 getLog().debug(sm.getString("abstractResource.getContentFail", 
getWebappPath()), ioe);
@@ -276,7 +280,7 @@ public class FileResource extends AbstractResource {
             try {
                 result = str.getBytes(StandardCharsets.UTF_8);
             } catch (Exception e) {
-                result = null;
+                return null;
             }
         }
         return result;
diff --git a/java/org/apache/catalina/webresources/LocalStrings.properties 
b/java/org/apache/catalina/webresources/LocalStrings.properties
index 0b4fd31e22..267fbc79f5 100644
--- a/java/org/apache/catalina/webresources/LocalStrings.properties
+++ b/java/org/apache/catalina/webresources/LocalStrings.properties
@@ -19,7 +19,6 @@ abstractArchiveResourceSet.archiveEntryFail=Failed to obtain 
an entry from the a
 abstractArchiveResourceSet.baseUrlFail=Failed to build the base URL for the 
archive [{0}]
 abstractArchiveResourceSet.manifestFail=Failed to read the manifest from the 
archive [{0}]
 abstractArchiveResourceSet.multiReleaseFail=Failed to determine if the archive 
[{0}] is a multi-release JAR
-abstractArchiveResourceSet.startFail=Failed to start the resource set
 abstractArchiveResourceSet.setReadOnlyFalse=Archive based WebResourceSets such 
as those based on JARs are hard-coded to be read-only and may not be configured 
to be read-write
 
 abstractFileResourceSet.canonicalfileCheckFailed=Resource for web application 
[{0}] at path [{1}] was not loaded as the canonical path [{2}] did not match. 
Use of symlinks is one possible cause.
@@ -31,6 +30,8 @@ abstractResource.getContentTooLarge=Unable to return [{0}] as 
a byte array since
 
 abstractResourceSet.checkPath=The requested path [{0}] is not valid. It must 
begin with "/".
 
+abstractSingleArchiveResourceSet.startFail=Failed to start the resource set
+
 cache.addFail=Unable to add the resource at [{0}] to the cache for web 
application [{1}] because there was insufficient free space available after 
evicting expired cache entries - consider increasing the maximum size of the 
cache
 cache.backgroundEvictFail=The background cache eviction process was unable to 
free [{0}] percent of the cache for Context [{1}] - consider increasing the 
maximum size of the cache. After eviction approximately [{2}] KiB of data 
remained in the cache.
 cache.objectMaxSizeTooBig=The value of [{0}] KiB for objectMaxSize is larger 
than the limit of maxSize/20 so has been reduced to [{1}] KiB


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to