You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Ted Husted <hu...@apache.org> on 2001/11/21 17:13:08 UTC

Re: cvs commit: jakarta-struts/src/share/org/apache/struts/uploadBufferedMultipartInputStream.java MultipartIterator.java

Can you boil this down for an entry to the release notes?

"SCHACHTER,MICHAEL (HP-NewJersey,ex2)" wrote:
> 
> Ted,
> 
> Unless someone else (Martin?) improved it, the problem that I think
> you're talking about wasn't addressed. Are you referring to this bug:
> 
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4170
> 
> The following bugs were addressed:
> 
> #3828, problem with equals() method (possibly because of file text
> containing PGP signature)
> 
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=3828
> 
> #4427, where bytes can be lost when using the readLine(byte[],int,int).
> this fix no longer affects the actual multipart form handling in struts,
> just anyone using the MultipartIterator class on it's own.
> 
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4427
> 
> #4701, report a premature closing of the input stream, instead of
> leaving it up to a NullPointerException
> 
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4701
> 
> -----Original Message-----
> From: Ted Husted [mailto:husted@apache.org]
> Sent: Wednesday, November 21, 2001 6:50 AM
> To: Struts Developers List
> Subject: Re: cvs commit:
> jakarta-struts/src/share/org/apache/struts/upload
> BufferedMultipartInputStream.java MultipartIterator.java
> 
> So, in the release notes (nightly and 1.0.1) we're saying
> 
>     <li>Improved error-handling on out of bounds conditions</li>
> 
> Does that cover well-enough what we're doing here?
> 
> mschachter@apache.org wrote:
> >
> > 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/BufferedMultipartInputStre
> am.java
> >
> >   Index: BufferedMultipartInputStream.java
> >   ===================================================================
> >   RCS file:
> /home/cvs/jakarta-struts/src/share/org/apache/struts/upload/BufferedMultipar
> tInputStream.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/MultipartIterato
> r.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:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/struts/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>