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

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


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 40e1eeea1f Align getContent() behaviour
40e1eeea1f is described below

commit 40e1eeea1f31f3637fd5431c68d685b4c53a660b
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 07c0415508..3c8544d9bb 100644
--- a/java/org/apache/catalina/webresources/AbstractArchiveResource.java
+++ b/java/org/apache/catalina/webresources/AbstractArchiveResource.java
@@ -205,8 +205,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 58d6542cdb..a124e7c518 100644
--- 
a/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
+++ 
b/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
@@ -66,7 +66,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 9eaaae8aea..2c7a0ce804 100644
--- a/java/org/apache/catalina/webresources/FileResource.java
+++ b/java/org/apache/catalina/webresources/FileResource.java
@@ -259,6 +259,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);
@@ -275,7 +279,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 0ad77fb288..d4a23d9363 100644
--- a/java/org/apache/catalina/webresources/LocalStrings.properties
+++ b/java/org/apache/catalina/webresources/LocalStrings.properties
@@ -22,7 +22,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.
@@ -34,6 +33,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