Skip to content

Commit

Permalink
Update the internal fork of Commons FileUpload to afdedc9. This pulls…
Browse files Browse the repository at this point in the history
… in a fix to improve the performance with large multipart boundaries and some Javadoc improvements.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc8.5.x/trunk@1757203 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Aug 22, 2016
1 parent 011cf1e commit 987cc4d
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 29 deletions.
37 changes: 28 additions & 9 deletions SVN-MERGE.txt → MERGE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ ideal. These include:
- potential conflicts if a web application ships with the same JAR
- a large JAR where Tomcat only depends on a small fraction

There are various approaches taken to dealing with this. One of those approaches
is to svn copy the classes to the Tomcat source tree, modify them (always with a
package rename, sometimes with additional changes) and then keep them in sync
with the original via regular svn merges. This file keeps track of these copies
to assist committers in keeping them up to date.

SVN
===

For sources hosted in svn the approache is to svn copy the classes to the Tomcat
source tree, modify them (always with a package rename, sometimes with
additional changes) and then keep them in sync with the original via regular svn
merges. This file keeps track of these copies to assist committers in keeping
them up to date.

BCEL
org.apache.tomcat.util.bcel is copied from:
Expand All @@ -40,14 +44,29 @@ org.apache.tomcat.dbcp.pool2 is copied from:
/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2

FileUpload
org.apache.tomcat.util.http.fileupload is copied from:
/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload
Note: Tomcat's copy of fileupload also includes classes copied manually (rather
than svn copied) from Commons IO.
This used to be hosted in svn. All changes up to the point where FileUpload was
migrated to git have been merged.

Codec
org.apache.tomcat.util.codec is copied from:
/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/
Note: Only classes required for Base64 encoding/decoding. The rest are removed.


GIT
===

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.
59 changes: 45 additions & 14 deletions java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ private void notifyListener() {
*/
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.
*/
Expand Down Expand Up @@ -302,12 +307,14 @@ public MultipartStream(InputStream input,
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;
Expand Down Expand Up @@ -453,6 +460,31 @@ public void setBoundary(byte[] boundary)
}
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++;
}
}
}

/**
Expand Down Expand Up @@ -575,6 +607,7 @@ public boolean skipPreamble() throws IOException {
// 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();
Expand All @@ -590,6 +623,7 @@ public boolean skipPreamble() throws IOException {
boundaryLength = boundary.length;
boundary[0] = CR;
boundary[1] = LF;
computeBoundaryTable();
}
}

Expand Down Expand Up @@ -645,23 +679,20 @@ protected int findByte(byte value,
* 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;

int bufferPos = this.head;
int tablePos = 0;

while (bufferPos < this.tail) {
while (tablePos >= 0 && buffer[bufferPos] != boundary[tablePos]) {
tablePos = boundaryTable[tablePos];
}
for (match = 1; match < boundaryLength; match++) {
if (buffer[first + match] != boundary[match]) {
break;
}
bufferPos++;
tablePos++;
if (tablePos == boundaryLength) {
return bufferPos - boundaryLength;
}
}
if (match == boundaryLength) {
return first - 1;
}
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void checkLimit() throws IOException {
*
* @return the next byte of data, or <code>-1</code> if the end of the
* stream is reached.
* @exception IOException if an I/O error occurs.
* @throws IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
*/
@Override
Expand Down Expand Up @@ -120,11 +120,11 @@ public int read() throws IOException {
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the stream has been reached.
* @exception NullPointerException If <code>b</code> is <code>null</code>.
* @exception IndexOutOfBoundsException If <code>off</code> is negative,
* @throws NullPointerException If <code>b</code> is <code>null</code>.
* @throws IndexOutOfBoundsException If <code>off</code> is negative,
* <code>len</code> is negative, or <code>len</code> is greater than
* <code>b.length - off</code>
* @exception IOException if an I/O error occurs.
* @throws IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
*/
@Override
Expand Down Expand Up @@ -154,7 +154,7 @@ public boolean isClosed() throws IOException {
* This
* method simply performs <code>in.close()</code>.
*
* @exception IOException if an I/O error occurs.
* @throws IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private QuotedPrintableDecoder() {
* @param out The output stream used to return the decoded data.
*
* @return the number of bytes produced.
* @exception IOException if aproblem occurs during either decoding or
* @throws IOException if a problem occurs during either decoding or
* writing to the stream
*/
public static int decode(byte[] data, OutputStream out) throws IOException {
Expand Down
5 changes: 5 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 987cc4d

Please sign in to comment.