@@ -2589,13 +2589,29 @@ private void parseParts(boolean explicit) {
25892589 upload .setFileItemFactory (factory );
25902590 upload .setFileSizeMax (mce .getMaxFileSize ());
25912591 upload .setSizeMax (mce .getMaxRequestSize ());
2592- if (maxParameterCount > -1 ) {
2593- // There is a limit. The limit for parts needs to be reduced by
2594- // the number of parameters we have already parsed.
2595- // Must be under the limit else parsing parameters would have
2596- // triggered an exception.
2597- upload .setFileCountMax (maxParameterCount - parameters .size ());
2592+ upload .setPartHeaderSizeMax (connector .getMaxPartHeaderSize ());
2593+ /*
2594+ * There are two independent limits on the number of parts.
2595+ *
2596+ * 1. The limit based on parameters. This is maxParameterCount less the number of parameters already processed.
2597+ *
2598+ * 2. The limit based on parts. This is maxPartCount.
2599+ *
2600+ * The lower of these two limits will be applied to this request.
2601+ *
2602+ * Note: Either of both limits may be set to -1 (unlimited).
2603+ */
2604+ int partLimit = maxParameterCount ;
2605+ if (partLimit > -1 ) {
2606+ partLimit = partLimit - parameters .size ();
2607+ }
2608+ int maxPartCount = connector .getMaxPartCount ();
2609+ if (maxPartCount > -1 ) {
2610+ if (partLimit < 0 || partLimit > maxPartCount ) {
2611+ partLimit = maxPartCount ;
2612+ }
25982613 }
2614+ upload .setFileCountMax (partLimit );
25992615
26002616 parts = new ArrayList <>();
26012617 try {
0 commit comments