This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new a51e4bedcc Align size tracking for multipart requests with
FileUpload's use of long
a51e4bedcc is described below
commit a51e4bedccfafd35b7cdd0ee3e22267dee9f90db
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Jul 1 20:22:16 2025 +0100
Align size tracking for multipart requests with FileUpload's use of long
---
java/org/apache/catalina/connector/Request.java | 13 +++++++------
webapps/docs/changelog.xml | 4 ++++
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/java/org/apache/catalina/connector/Request.java
b/java/org/apache/catalina/connector/Request.java
index 2b34c03534..88d2c82c78 100644
--- a/java/org/apache/catalina/connector/Request.java
+++ b/java/org/apache/catalina/connector/Request.java
@@ -2575,23 +2575,23 @@ public class Request implements HttpServletRequest {
try {
List<FileItem> items = upload.parseRequest(new
ServletRequestContext(this));
int maxPostSize = getConnector().getMaxPostSize();
- int postSize = 0;
+ long postSize = 0;
Charset charset = getCharset();
for (FileItem item : items) {
ApplicationPart part = new ApplicationPart(item, location);
- parts.add(part);
if (part.getSubmittedFileName() == null) {
String name = part.getName();
if (maxPostSize >= 0) {
// Have to calculate equivalent size. Not completely
// accurate but close enough.
- postSize += name.getBytes(charset).length;
+ // Name
+ postSize = Math.addExact(postSize,
name.getBytes(charset).length);
// Equals sign
- postSize++;
+ postSize = Math.addExact(postSize, 1);
// Value length
- postSize += (int) part.getSize();
+ postSize = Math.addExact(postSize, part.getSize());
// Value separator
- postSize++;
+ postSize = Math.addExact(postSize, 1);
if (postSize > maxPostSize) {
throw new
IllegalStateException(sm.getString("coyoteRequest.maxPostSizeExceeded"));
}
@@ -2607,6 +2607,7 @@ public class Request implements HttpServletRequest {
// Adjust the limit to account for a file part which is
not added to the parameter map.
maxParameterCount--;
}
+ parts.add(part);
}
} catch (InvalidContentTypeException e) {
partsParseException = new ServletException(e);
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index f56d589344..3402a7c235 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -132,6 +132,10 @@
multipart uploads with non-file parts when the parts were processed
before query string parameters. (markt)
</fix>
+ <fix>
+ Align size tracking for multipart requests with FileUpload's use of
+ <code>long</code>. (schultz)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]