mschachter 01/11/20 21:04:36
Modified: src/share/org/apache/struts/upload Tag: STRUTS_1_0_BRANCH
BufferedMultipartInputStream.java
MultipartIterator.java
Log:
- fix #3828, equals() method problem (ported from main branch)
Submitted By: Curt Hagenlocher
- fix #4427, lost bytes on read(byte[],int,int) (need to port to main branch)
Submitted By: Mike Goutrie
- fix #4701, premature end of input stream not reported (need to port to main
branch)
Submitted By: Roland Huss
Revision Changes Path
No revision
No revision
1.3.2.4 +40 -40
jakarta-struts/src/share/org/apache/struts/upload/BufferedMultipartInputStream.java
Index: BufferedMultipartInputStream.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/upload/BufferedMultipartInputStream.java,v
retrieving revision 1.3.2.3
retrieving revision 1.3.2.4
diff -u -r1.3.2.3 -r1.3.2.4
--- BufferedMultipartInputStream.java 2001/10/05 20:26:09 1.3.2.3
+++ BufferedMultipartInputStream.java 2001/11/21 05:04:36 1.3.2.4
@@ -10,60 +10,60 @@
* readLine() method.
*/
public class BufferedMultipartInputStream extends InputStream {
-
+
/**
* The underlying InputStream used by this class
*/
protected InputStream inputStream;
-
+
/**
* The byte array used to hold buffered data
*/
protected byte[] buffer;
-
+
/**
* The current offset we're at in the buffer's byte array
*/
protected int bufferOffset = 0;
-
+
/**
* The size of the byte array buffer
*/
protected int bufferSize = 8192;
-
+
/**
* The number of bytes read from the underlying InputStream that are
* in the buffer
*/
protected int bufferLength = 0;
-
+
/**
* The total number of bytes read so far
*/
protected int totalLength = 0;
-
+
/**
* The content length of the multipart data
*/
protected long contentLength;
-
+
/**
* The maximum allowed size for the multipart data, or -1 for an unlimited
* maximum file length
*/
protected long maxSize = -1;
-
+
/**
* Whether or not bytes up to the Content-Length have been read
*/
protected boolean contentLengthMet = false;
-
+
/**
* Whether or not bytes up to the maximum length have been read
*/
protected boolean maxLengthMet = false;
-
-
+
+
/**
* Public constructor for this class, just wraps the InputStream
* given
@@ -81,14 +81,14 @@
this.bufferSize = bufferSize;
this.contentLength = contentLength;
this.maxSize = maxSize;
-
+
if (maxSize < contentLength) {
throw new MaxLengthExceededException(maxSize);
}
buffer = new byte[bufferSize];
fill();
}
-
+
/**
* This method returns the number of available bytes left to read
* in the buffer before it has to be refilled
@@ -96,50 +96,50 @@
public int available() {
return bufferLength - bufferOffset;
}
-
+
/**
* This method attempts to close the underlying InputStream
*/
public void close() throws IOException {
inputStream.close();
}
-
+
/**
* This method calls on the mark() method of the underlying InputStream
*/
public void mark(int position) {
- inputStream.mark(position);
- }
-
+ inputStream.mark(position);
+ }
+
/**
* This method calls on the markSupported() method of the underlying InputStream
* @return Whether or not the underlying InputStream supports marking
*/
public boolean markSupported() {
- return inputStream.markSupported();
+ return inputStream.markSupported();
}
-
+
/**
* @return true if the maximum length has been reached, false otherwise
*/
public boolean maxLengthMet() {
return maxLengthMet;
}
-
+
/**
* @return true if the content length has been reached, false otherwise
*/
public boolean contentLengthMet() {
return contentLengthMet;
}
-
+
/**
* This method returns the next byte in the buffer, and refills it if necessary.
* @return The next byte read in the buffer, or -1 if the end of the stream has
* been reached
*/
public int read() throws IOException {
-
+
if (maxLengthMet) {
throw new MaxLengthExceededException(maxSize);
}
@@ -149,34 +149,34 @@
if (buffer == null) {
return -1;
}
-
- if (bufferOffset < bufferLength) {
- return (int)(char) buffer[bufferOffset++];
+
+ if (bufferOffset < bufferLength) {
+ return (int)(char) buffer[bufferOffset++];
}
fill();
- return read();
+ return read();
}
-
+
/**
* This method populates the byte array <code>b</code> with data up to
* <code>b.length</code> bytes
*/
public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
+ return read(b, 0, b.length);
}
-
+
/**
- * This method populates the byte array <code>b</code> with data up to
+ * This method populates the byte array <code>b</code> with data up to
* <code>length</code> starting at b[offset]
*/
public int read(byte[] b, int offset, int length) throws IOException {
-
- int count = 0;
+
int read = read();
if (read == -1) {
return -1;
}
-
+ int count = 1;
+
while ((read != -1) && (count < length)) {
b[offset] = (byte) read;
read = read();
@@ -185,20 +185,20 @@
}
return count;
}
-
+
/**
* This method reads into the byte array <code>b</code> until
* a newline ('\n') character is encountered or the number of bytes
* specified by <code>length</code> have been read
*/
public int readLine(byte[] b, int offset, int length) throws IOException {
-
+
int count = 0;
int read = read();
if (read == -1) {
return -1;
}
-
+
while ((read != -1) && (count < length)) {
if (read == '\n')
break;
@@ -236,7 +236,7 @@
* InputStream
*/
public void reset() throws IOException {
- inputStream.reset();
+ inputStream.reset();
}
/**
@@ -270,7 +270,7 @@
else {
bufferLength = bytesRead;
totalLength += bytesRead;
- bufferOffset = 0;
+ bufferOffset = 0;
}
}
}
1.13.2.6 +8 -0
jakarta-struts/src/share/org/apache/struts/upload/MultipartIterator.java
Index: MultipartIterator.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/upload/MultipartIterator.java,v
retrieving revision 1.13.2.5
retrieving revision 1.13.2.6
diff -u -r1.13.2.5 -r1.13.2.6
--- MultipartIterator.java 2001/10/05 20:26:09 1.13.2.5
+++ MultipartIterator.java 2001/11/21 05:04:36 1.13.2.6
@@ -486,6 +486,10 @@
BufferedOutputStream fos = new BufferedOutputStream(new
FileOutputStream(tempFile),
diskBufferSize);
byte[] lineBuffer = inputStream.readLine();
+ if (lineBuffer == null)
+ {
+ throw new IOException("Premature end of stream while reading multipart
request");
+ }
int bytesRead = lineBuffer.length;
boolean cutCarriage = false;
@@ -511,6 +515,10 @@
cutNewline = true;
fos.write(lineBuffer, 0, bytesRead);
lineBuffer = inputStream.readLine();
+ if (lineBuffer == null)
+ {
+ throw new IOException("Premature end of stream while
reading multipart request");
+ }
bytesRead = lineBuffer.length;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>