Detect all common size exceptions from Tomcat and Commons FileUpload 2.x

Closes gh-36317
This commit is contained in:
Juergen Hoeller
2026-02-13 16:19:46 +01:00
parent 9a002a77b2
commit e8e24e65d2
2 changed files with 72 additions and 3 deletions
@@ -117,10 +117,11 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe
// MaxUploadSizeExceededException ?
Throwable cause = ex;
do {
String msg = cause.getMessage();
String msg = cause.toString();
if (msg != null) {
msg = msg.toLowerCase(Locale.ROOT);
if ((msg.contains("exceed") && (msg.contains("size") || msg.contains("length"))) ||
if (((msg.contains("exceed") || msg.contains("limit")) &&
(msg.contains("size") || msg.contains("length") || msg.contains("count"))) ||
(msg.contains("request") && (msg.contains("big") || msg.contains("large")))) {
throw new MaxUploadSizeExceededException(-1, ex);
}
@@ -266,7 +267,7 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe
if (dest.isAbsolute() && !dest.exists()) {
// Servlet Part.write is not guaranteed to support absolute file paths:
// may translate the given path to a relative location within a temp dir
// (for example, on Jetty whereas Tomcat detects absolute paths).
// (for example, on Jetty whereas Tomcat and Undertow detect absolute paths).
// At least we offloaded the file from memory storage; it'll get deleted
// from the temp dir eventually in any case. And for our user's purposes,
// we can manually copy it to the requested location as a fallback.