Skip to content

Commit 0747275

Browse files
committed
Detect Undertow RequestTooBigException message in handleParseFailure
Closes gh-32549
1 parent 47c9c7e commit 0747275

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

spring-web/src/main/java/org/springframework/web/multipart/support/StandardMultipartHttpServletRequest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -118,7 +118,8 @@ protected void handleParseFailure(Throwable ex) {
118118
String msg = cause.getMessage();
119119
if (msg != null) {
120120
msg = msg.toLowerCase();
121-
if (msg.contains("exceed") && (msg.contains("size") || msg.contains("length"))) {
121+
if ((msg.contains("exceed") && (msg.contains("size") || msg.contains("length"))) ||
122+
(msg.contains("request") && (msg.contains("big") || msg.contains("large")))) {
122123
throw new MaxUploadSizeExceededException(-1, ex);
123124
}
124125
}

spring-web/src/test/java/org/springframework/web/multipart/support/StandardMultipartHttpServletRequestTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ void jetty12MaxLengthExceededException() {
123123
.isThrownBy(() -> requestWithException(ex)).withCause(ex);
124124
}
125125

126+
@Test // gh-32549
127+
void undertowRequestTooBigException() {
128+
IOException ex = new IOException("Connection terminated as request was larger than 10000");
129+
130+
assertThatExceptionOfType(MaxUploadSizeExceededException.class)
131+
.isThrownBy(() -> requestWithException(ex)).withCause(ex);
132+
}
133+
126134

127135
private static StandardMultipartHttpServletRequest requestWithPart(String name, String disposition, String content) {
128136
MockHttpServletRequest request = new MockHttpServletRequest();
@@ -142,4 +150,14 @@ public Collection<Part> getParts() throws ServletException {
142150
return new StandardMultipartHttpServletRequest(request);
143151
}
144152

153+
private static StandardMultipartHttpServletRequest requestWithException(IOException ex) {
154+
MockHttpServletRequest request = new MockHttpServletRequest() {
155+
@Override
156+
public Collection<Part> getParts() throws IOException {
157+
throw ex;
158+
}
159+
};
160+
return new StandardMultipartHttpServletRequest(request);
161+
}
162+
145163
}

0 commit comments

Comments
 (0)