Detect Jetty 12 "max length exceeded" message in handleParseFailure

Closes gh-31850
This commit is contained in:
Juergen Hoeller
2023-12-18 16:18:27 +01:00
parent 24f8eac12a
commit 045c5dc1b4
2 changed files with 55 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -112,13 +112,21 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe
}
protected void handleParseFailure(Throwable ex) {
String msg = ex.getMessage();
if (msg != null) {
msg = msg.toLowerCase();
if (msg.contains("size") && msg.contains("exceed")) {
throw new MaxUploadSizeExceededException(-1, ex);
// MaxUploadSizeExceededException ?
Throwable cause = ex;
do {
String msg = cause.getMessage();
if (msg != null) {
msg = msg.toLowerCase();
if (msg.contains("exceed") && (msg.contains("size") || msg.contains("length"))) {
throw new MaxUploadSizeExceededException(-1, ex);
}
}
cause = cause.getCause();
}
while (cause != null);
// General MultipartException
throw new MultipartException("Failed to parse multipart servlet request", ex);
}