Author: markt
Date: Mon Aug 22 15:12:18 2016
New Revision: 1757195
URL: http://svn.apache.org/viewvc?rev=1757195&view=rev
Log:
Update the internal fork of Commons FileUpload to afdedc9. This pulls in a fix
to improve the performance with large multipart boundaries.
Modified:
tomcat/trunk/MERGE.txt
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/MERGE.txt
URL:
http://svn.apache.org/viewvc/tomcat/trunk/MERGE.txt?rev=1757195&r1=1757194&r2=1757195&view=diff
==============================================================================
--- tomcat/trunk/MERGE.txt (original)
+++ tomcat/trunk/MERGE.txt Mon Aug 22 15:12:18 2016
@@ -56,8 +56,17 @@ Note: Only classes required for Base64 e
GIT
===
-Process TBD
+Updates from Git are applied manually via patch files. Patch files are
generated
+using:
+git diff <last SHA1>:<sub-tree> HEAD:<sub-tree> > temp.patch
+The more recently merged SHA1 for the component below should be updated after
+the patch file has been applied and committed
FileUpload
+Sub-tree:
+src/main/java/org/apache/commons/fileupload
+The SHA1 ID for the most recent commit to be merged to Tomcat is:
+86b11bbc1437a12fa64bc1484c4edc0bdd5a0966
+
Note: Tomcat's copy of fileupload also includes classes copied manually (rather
than svn copied) from Commons IO.
Modified:
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java?rev=1757195&r1=1757194&r2=1757195&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
(original)
+++
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
Mon Aug 22 15:12:18 2016
@@ -226,6 +226,11 @@ public class MultipartStream {
private final byte[] boundary;
/**
+ * The table for Knuth-Morris-Pratt search algorithm
+ */
+ private int[] boundaryTable;
+
+ /**
* The length of the buffer used for processing the request.
*/
private final int bufSize;
@@ -302,12 +307,14 @@ public class MultipartStream {
this.notifier = pNotifier;
this.boundary = new byte[this.boundaryLength];
+ this.boundaryTable = new int[this.boundaryLength + 1];
this.keepRegion = this.boundary.length;
System.arraycopy(BOUNDARY_PREFIX, 0, this.boundary, 0,
BOUNDARY_PREFIX.length);
System.arraycopy(boundary, 0, this.boundary, BOUNDARY_PREFIX.length,
boundary.length);
+ computeBoundaryTable();
head = 0;
tail = 0;
@@ -453,6 +460,31 @@ public class MultipartStream {
}
System.arraycopy(boundary, 0, this.boundary, BOUNDARY_PREFIX.length,
boundary.length);
+ computeBoundaryTable();
+ }
+
+ /**
+ * Compute the table used for Knuth-Morris-Pratt search algorithm.
+ */
+ private void computeBoundaryTable() {
+ int position = 2;
+ int candidate = 0;
+
+ boundaryTable[0] = -1;
+ boundaryTable[1] = 0;
+
+ while (position <= boundaryLength) {
+ if (boundary[position - 1] == boundary[candidate]) {
+ boundaryTable[position] = candidate + 1;
+ candidate++;
+ position++;
+ } else if (candidate > 0) {
+ candidate = boundaryTable[candidate];
+ } else {
+ boundaryTable[position] = 0;
+ position++;
+ }
+ }
}
/**
@@ -575,6 +607,7 @@ public class MultipartStream {
// First delimiter may be not preceeded with a CRLF.
System.arraycopy(boundary, 2, boundary, 0, boundary.length - 2);
boundaryLength = boundary.length - 2;
+ computeBoundaryTable();
try {
// Discard all data up to the delimiter.
discardBodyData();
@@ -590,6 +623,7 @@ public class MultipartStream {
boundaryLength = boundary.length;
boundary[0] = CR;
boundary[1] = LF;
+ computeBoundaryTable();
}
}
@@ -645,23 +679,20 @@ public class MultipartStream {
* not found.
*/
protected int findSeparator() {
- int first;
- int match = 0;
- int maxpos = tail - boundaryLength;
- for (first = head; first <= maxpos && match != boundaryLength;
first++) {
- first = findByte(boundary[0], first);
- if (first == -1 || first > maxpos) {
- return -1;
- }
- for (match = 1; match < boundaryLength; match++) {
- if (buffer[first + match] != boundary[match]) {
- break;
- }
+
+ int bufferPos = this.head;
+ int tablePos = 0;
+
+ while (bufferPos < this.tail) {
+ while (tablePos >= 0 && buffer[bufferPos] != boundary[tablePos]) {
+ tablePos = boundaryTable[tablePos];
+ }
+ bufferPos++;
+ tablePos++;
+ if (tablePos == boundaryLength) {
+ return bufferPos - boundaryLength;
}
}
- if (match == boundaryLength) {
- return first - 1;
- }
return -1;
}
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1757195&r1=1757194&r2=1757195&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Mon Aug 22 15:12:18 2016
@@ -286,6 +286,11 @@
Update the internal fork of Commons Codec to r1757174. Code formatting
changes only. (markt)
</update>
+ <update>
+ Update the internal fork of Commons FileUpload to afdedc9. This pulls
in
+ a fix to improve the performance with large multipart boundaries.
+ (markt)
+ </update>
</changelog>
</subsection>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]