You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by ms...@apache.org on 2001/04/18 04:27:19 UTC
cvs commit: jakarta-struts/src/share/org/apache/struts/upload MultipartIterator.java BufferedMultipartInputStream.java
mschachter 01/04/17 19:27:19
Modified: src/share/org/apache/struts/upload MultipartIterator.java
BufferedMultipartInputStream.java
Log:
- Fixed issue with maxFileSize
- Added more descriptive IOExceptions
Revision Changes Path
1.11 +3 -11 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- MultipartIterator.java 2001/04/11 22:56:20 1.10
+++ MultipartIterator.java 2001/04/18 02:27:18 1.11
@@ -214,7 +214,7 @@
element = new MultipartElement(name, filename, contentType, elementFile);
} catch (IOException ioe) {
- throw new ServletException("IOException while reading file element: ioe.getMessage()", ioe);
+ throw new ServletException("IOException while reading file element: " + ioe.getMessage(), ioe);
}
}
else {
@@ -228,13 +228,6 @@
while ((line != null) && (!line.startsWith(boundary))) {
textData.append(line);
line = readLine();
-
- if (maxSize > -1) {
- if (totalLength > maxSize) {
- throw new ServletException("Multipart data size exceeds the maximum " +
- "allowed post size");
- }
- }
}
if (textData.length() > 0) {
@@ -322,9 +315,8 @@
}
catch (IOException ioe) {
- throw new ServletException("MultipartIterator.parseRequest(): " +
- "IOException while trying to obtain " +
- "ServletInputStream");
+ throw new ServletException("Problem while reading request: " +
+ ioe.getMessage(), ioe);
}
if ((boundary == null) || (boundary.length() < 1)) {
1.2 +53 -6 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BufferedMultipartInputStream.java 2001/04/11 22:56:19 1.1
+++ BufferedMultipartInputStream.java 2001/04/18 02:27:19 1.2
@@ -52,7 +52,17 @@
*/
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
@@ -70,6 +80,11 @@
this.bufferSize = bufferSize;
this.contentLength = contentLength;
this.maxSize = maxSize;
+
+ if (maxSize < contentLength) {
+ throw new IOException("Posted Content-Length of " + contentLength +
+ " bytes exceeds maximum post size of " + maxSize + " bytes");
+ }
buffer = new byte[bufferSize];
fill();
}
@@ -105,11 +120,34 @@
}
/**
+ * @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 {
+ public int read() throws IOException {
+
+ if (maxLengthMet) {
+ throw new IOException("Maximum post length of " + maxSize + " bytes " +
+ "has been reached");
+ }
+ if (contentLengthMet) {
+ throw new IOException("Content-Length of " + contentLength + " bytes " +
+ "has been exceeded");
+ }
if (buffer == null) {
return -1;
}
@@ -190,12 +228,21 @@
protected void fill() throws IOException {
if ((bufferOffset > -1) && (bufferLength > -1)) {
- int length = Math.min(bufferSize, (int) contentLength);
- if (maxSize > -1) {
- length = Math.min(length, (int) maxSize);
+ int length = Math.min(bufferSize, (((int) contentLength+1) - totalLength));
+ if (length == 0) {
+ contentLengthMet = true;
}
+ if ((maxSize > -1) && (length > 0)){
+ length = Math.min(length, ((int) maxSize - totalLength));
+ if (length == 0) {
+ maxLengthMet = true;
+ }
+ }
- int bytesRead = inputStream.read(buffer, 0, length);
+ int bytesRead = -1;
+ if (length > 0) {
+ bytesRead = inputStream.read(buffer, 0, length);
+ }
if (bytesRead == -1) {
buffer = null;
bufferOffset = -1;
@@ -204,7 +251,7 @@
else {
bufferLength = bytesRead;
totalLength += bytesRead;
- bufferOffset = 0;
+ bufferOffset = 0;
}
}
}