mschachter 01/09/24 09:41:37
Modified: src/share/org/apache/struts/upload
BufferedMultipartInputStream.java
MultipartIterator.java
Log:
- fixed file-mangling bug (#3702)
- fixed long line bug (#2503)
CVS: ----------------------------------------------------------------------
Revision Changes Path
1.5 +21 -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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BufferedMultipartInputStream.java 2001/07/02 20:15:33 1.4
+++ BufferedMultipartInputStream.java 2001/09/24 16:41:37 1.5
@@ -2,6 +2,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
/**
* This class implements buffering for an InputStream as well as a
@@ -204,15 +205,29 @@
b[offset] = (byte) read;
count++;
offset++;
- //make sure that we don't ignore the last character if a
- //newline isn't encountered
- if (count < length) {
- read = read();
- }
+ read = read();
}
return count;
}
-
+
+ /**
+ * This method reads a line, regardless of length.
+ * @return A byte array representing the line.
+ */
+ public byte[] readLine() throws IOException {
+
+ int read = read();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ while (read != -1) {
+ if (read == '\n') {
+ return baos.toByteArray();
+ }
+ baos.write(read);
+ read = read();
+ }
+ return baos.toByteArray();
+ }
+
/**
* This method makes a call to the reset() method of the underlying
* InputStream
1.17 +15 -20
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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- MultipartIterator.java 2001/07/06 20:00:37 1.16
+++ MultipartIterator.java 2001/09/24 16:41:37 1.17
@@ -147,7 +147,7 @@
}
else {
//default to system-wide tempdir
- this.tempDir = System.getProperty("java.io.tmpdir");
+ tempDir = System.getProperty("java.io.tmpdir");
}
parseRequest();
}
@@ -447,8 +447,8 @@
* Reads the input stream until it reaches a new line
*/
protected String readLine() throws ServletException,
UnsupportedEncodingException {
-
- byte[] bufferByte = new byte[bufferSize];
+
+ byte[] bufferByte;
int bytesRead;
if (totalLength >= contentLength) {
@@ -456,9 +456,8 @@
}
try {
- bytesRead = inputStream.readLine(bufferByte,
- 0,
- bufferSize);
+ bufferByte = inputStream.readLine();
+ bytesRead = bufferByte.length;
}
catch (IOException ioe) {
throw new ServletException("IOException while reading multipart
request: " +
@@ -481,8 +480,8 @@
File tempFile = File.createTempFile("strts", null, new File(tempDir));
BufferedOutputStream fos = new BufferedOutputStream(new
FileOutputStream(tempFile),
diskBufferSize);
- byte[] lineBuffer = new byte[MAX_LINE_SIZE];
- int bytesRead = inputStream.readLine(lineBuffer, 0, MAX_LINE_SIZE);
+ byte[] lineBuffer = inputStream.readLine();
+ int bytesRead = lineBuffer.length;
boolean cutCarriage = false;
boolean cutNewline = false;
@@ -493,33 +492,29 @@
if (cutCarriage) {
fos.write('\r');
- cutCarriage = false;
}
if (cutNewline) {
fos.write('\n');
- cutNewline = false;
}
+ cutCarriage = false;
if (bytesRead > 0) {
if (lineBuffer[bytesRead-1] == '\r') {
- //bytesRead--;
+ bytesRead--;
cutCarriage = true;
- fos.write(lineBuffer, 0, bytesRead-1);
}
- else {
- fos.write(lineBuffer, 0, bytesRead);
- }
- }
- if (bytesRead < MAX_LINE_SIZE) {
- cutNewline = true;
}
- bytesRead = inputStream.readLine(lineBuffer, 0,
MAX_LINE_SIZE);
+ cutNewline = true;
+ fos.write(lineBuffer, 0, bytesRead);
+ lineBuffer = inputStream.readLine();
+ bytesRead = lineBuffer.length;
}
}
catch (IOException ioe) {
fos.close();
tempFile.delete();
throw ioe;
- }
+ }
+
fos.flush();
fos.close();
return tempFile;