From d97eabba2fcb4c69d25befdcd4869ac87ebf9167 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 24 Mar 2020 10:50:10 +0100 Subject: [PATCH] Do not cache multipart MIME types in cache Prior to this commmit, "mutipart/*" MIME types would be cached by the `MimeTypeUtils` LRU cache. Since those MIME types are likely to have random boundaries in them, they can waste space in the LRU cache. This is not improving things since we're parsing them anyway. This commit skips the caching step for all "multipart" MIME types. Fixes gh-24767 --- .../src/main/java/org/springframework/util/MimeTypeUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java index 89609925bc..c369bb4ebc 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java +++ b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java @@ -193,6 +193,10 @@ public abstract class MimeTypeUtils { if (!StringUtils.hasLength(mimeType)) { throw new InvalidMimeTypeException(mimeType, "'mimeType' must not be empty"); } + // do not cache multipart mime types with random boundaries + if (mimeType.startsWith("multipart")) { + return parseMimeTypeInternal(mimeType); + } return cachedMimeTypes.get(mimeType); }