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 a037dee3c0 Avoid caching bogus 0 content length a037dee3c0 is described below commit a037dee3c0b001df37e3383aeba6adb879d4e459 Author: remm <r...@apache.org> AuthorDate: Thu Jan 9 16:29:24 2025 +0100 Avoid caching bogus 0 content length When using getResources, the actual webResource is not retrieved. If calling getContentLength, it would cache 0 as the content length. Also initialize the cached resource a bit more to avoid a very likely concurrent eviction if somehow the cache is full. Possible fix for 69527. --- java/org/apache/catalina/webresources/CachedResource.java | 10 +++++----- webapps/docs/changelog.xml | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/java/org/apache/catalina/webresources/CachedResource.java b/java/org/apache/catalina/webresources/CachedResource.java index 40fb323224..ff2be74844 100644 --- a/java/org/apache/catalina/webresources/CachedResource.java +++ b/java/org/apache/catalina/webresources/CachedResource.java @@ -85,6 +85,7 @@ public class CachedResource implements WebResource { this.root = root; this.webAppPath = path; this.ttl = ttl; + nextCheck = ttl + System.currentTimeMillis(); this.objectMaxSizeBytes = objectMaxSizeBytes; this.usesClassLoaderResources = usesClassLoaderResources; } @@ -247,6 +248,9 @@ public class CachedResource implements WebResource { @Override public long getContentLength() { + if (webResource == null) { + return Long.valueOf(0); + } /* * Cache the content length for two reasons. * @@ -263,11 +267,7 @@ public class CachedResource implements WebResource { if (cachedContentLength == null) { synchronized (cachedContentLengthLock) { if (cachedContentLength == null) { - if (webResource == null) { - cachedContentLength = Long.valueOf(0); - } else { - cachedContentLength = Long.valueOf(webResource.getContentLength()); - } + cachedContentLength = Long.valueOf(webResource.getContentLength()); } } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index b530bbeb98..6822035e97 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -123,6 +123,10 @@ attribute value will also be used by the default and WebDAV Servlets. (remm) </update> + <fix> + <bug>69527</bug>: Avoid rare cases where a cached resource could be set + with 0 content length, or could be evicted immediately. (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