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 e6ad02fb10 Simplify reading of request body for
x-www-form-urlencoded processing
e6ad02fb10 is described below
commit e6ad02fb10506618f7e03c472105462b5c2f1d61
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Jun 23 17:44:36 2023 +0100
Simplify reading of request body for x-www-form-urlencoded
processing
An incomplete body is the same as a client disconnect before the
request
body has been read as that is the only way a client can provide an
incomplete body.
---
java/org/apache/catalina/connector/Request.java | 31
++++++++++++++++++----
.../catalina/filters/FailedRequestFilter.java | 1 +
java/org/apache/tomcat/util/http/Parameters.java | 6 +++++
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/java/org/apache/catalina/connector/Request.java
b/java/org/apache/catalina/connector/Request.java
index 312b3f4e81..88de9be19a 100644
--- a/java/org/apache/catalina/connector/Request.java
+++ b/java/org/apache/catalina/connector/Request.java
@@ -17,6 +17,7 @@
package org.apache.catalina.connector;
import java.io.BufferedReader;
+import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -3115,10 +3116,7 @@ public class Request implements
HttpServletRequest {
formData = new byte[len];
}
try {
- if (readPostBody(formData, len) != len) {
-
parameters.setParseFailedReason(FailReason.REQUEST_BODY_INCOMPLETE);
- return;
- }
+ readPostBodyFully(formData, len);
} catch (IOException e) {
// Client disconnect
Context context = getContext();
@@ -3165,7 +3163,7 @@ public class Request implements
HttpServletRequest {
/**
- * Read post body in an array.
+ * Read post body into an array.
*
* @param body The bytes array in which the body will be read
* @param len The body length
@@ -3173,7 +3171,10 @@ public class Request implements
HttpServletRequest {
* @return the bytes count that has been read
*
* @throws IOException if an IO exception occurred
+ *
+ * @deprecated Unused. Will be removed in Tomcat 11.0.x onwards.
Use {@link #readPostBodyFully(byte[], int)}
*/
+ @Deprecated
protected int readPostBody(byte[] body, int len) throws
IOException {
int offset = 0;
@@ -3189,6 +3190,26 @@ public class Request implements
HttpServletRequest {
}
+ /**
+ * Read post body into an array.
+ *
+ * @param body The bytes array in which the body will be read
+ * @param len The body length
+ *
+ * @throws IOException if an IO exception occurred or EOF is
reached before the body has been fully read
+ */
+ protected void readPostBodyFully(byte[] body, int len) throws
IOException {
+ int offset = 0;
+ do {
+ int inputLen = getStream().read(body, offset, len - offset);