This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 266fbc953b Align size tracking for multipart requests with FileUpload's use of long 266fbc953b is described below commit 266fbc953b5d40b518e4eb10132e561bc6ae8c5a Author: Mark Thomas <ma...@apache.org> 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 760e728e28..042e199659 100644 --- a/java/org/apache/catalina/connector/Request.java +++ b/java/org/apache/catalina/connector/Request.java @@ -2467,23 +2467,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")); } @@ -2499,6 +2499,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 48ab93e696..e23bf7826e 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -187,6 +187,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: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org