Skip to content

Commit 927d66f

Browse files
committed
Align size tracking for multipart requests with FileUpload's use of long
1 parent 4347729 commit 927d66f

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

java/org/apache/catalina/connector/Request.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,23 +2715,23 @@ private void parseParts(boolean explicit) {
27152715
try {
27162716
List<FileItem> items = upload.parseRequest(new ServletRequestContext(this));
27172717
int maxPostSize = getConnector().getMaxPostSize();
2718-
int postSize = 0;
2718+
long postSize = 0;
27192719
Charset charset = getCharset();
27202720
for (FileItem item : items) {
27212721
ApplicationPart part = new ApplicationPart(item, location);
2722-
parts.add(part);
27232722
if (part.getSubmittedFileName() == null) {
27242723
String name = part.getName();
27252724
if (maxPostSize >= 0) {
27262725
// Have to calculate equivalent size. Not completely
27272726
// accurate but close enough.
2728-
postSize += name.getBytes(charset).length;
2727+
// Name
2728+
postSize = Math.addExact(postSize, name.getBytes(charset).length);
27292729
// Equals sign
2730-
postSize++;
2730+
postSize = Math.addExact(postSize, 1);
27312731
// Value length
2732-
postSize += part.getSize();
2732+
postSize = Math.addExact(postSize, part.getSize());
27332733
// Value separator
2734-
postSize++;
2734+
postSize = Math.addExact(postSize, 1);
27352735
if (postSize > maxPostSize) {
27362736
parameters.setParseFailedReason(FailReason.POST_TOO_LARGE);
27372737
throw new IllegalStateException(sm.getString("coyoteRequest.maxPostSizeExceeded"));
@@ -2748,6 +2748,7 @@ private void parseParts(boolean explicit) {
27482748
// Adjust the limit to account for a file part which is not added to the parameter map.
27492749
maxParameterCount--;
27502750
}
2751+
parts.add(part);
27512752
}
27522753

27532754
success = true;

webapps/docs/changelog.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@
128128
multipart uploads with non-file parts when the parts were processed
129129
before query string parameters. (markt)
130130
</fix>
131+
<fix>
132+
Align size tracking for multipart requests with FileUpload's use of
133+
<code>long</code>. (schultz)
134+
</fix>
131135
</changelog>
132136
</subsection>
133137
<subsection name="Coyote">

0 commit comments

Comments
 (0)