Re: 1.2.9 bug: InputStream from request throwing an exception

2000-09-05 Thread Joseph B. Ottinger

This message has little or no relevance to your actual bug.

However, I just looked at www.orionserver.com/bugzilla, and I don't see
this mentioned yet; to report bugs, there are two avenues to use. The
first should probably be bugzilla, in my mind, as this creates a visible
trail that everyone can follow, and the second is [EMAIL PROTECTED],
which has the advantage of being direct but can have relatively little
feedback.

Use bugzilla, too!

On Tue, 5 Sep 2000, Scott Lawrence wrote:

 Orion 1.2.9
 Windows 2000
 J2SE 1.3.0
 
 Bug: Underlying InputStream from request.getInputStream() throws an
 exception when the input stream should return more than 2048 bytes.
 
 Example: The following error occurs when running the JSP and servlet below.
 The underlying input stream seems to throw and exception during in.read(...)
 when trying to upload a file that's greater than 2048 (actually when the
 file + the extra multi encoding   2048).  I've tried this on Tomcat 3.2b
 and it works fine.  I've used similar code on older servers (not orion) and
 didn't have this problem.  I'm writing this to the users group as well in
 case others are having problems with this.  If you work with file uploading
 through forms, this will certainly hamper your progress.
 
 
 500 Internal Server Error
 java.lang.IndexOutOfBoundsException
   at com.evermind.server.http.ep.read(JAX)
   at InputStreamBug.doPost(InputStreamBug.java:21)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java)
   at com.evermind.server.http.du.rr(JAX)
   at com.evermind.server.http.du.forward(JAX)
   at com.evermind.server.http.d5.rx(JAX)
   at com.evermind.server.http.d5.rw(JAX)
   at com.evermind.util.f.run(JAX)
 
 InputStreamBug.jsp
 %@page contentType="text/html"%
 html
 headtitleInputStreamBug/title/head
 body
 FORM action='servlet/InputStreamBug' enctype='multipart/form-data'
 method='post'
 INPUT type='file' name='filename'BR
 INPUT type='submit' name='submit' value='Upload'
 /FORM
 /body
 /html
 
 
 InputStreamBug.java---
 import javax.servlet.*;
 import javax.servlet.http.*;
 import java.io.*;
 import java.util.*;
 
 public class InputStreamBug extends HttpServlet {
 /**
  * Reads the input stream and outputs the results to the output stream.
  */
 public void doPost(HttpServletRequest request, HttpServletResponse
 response)
 throws IOException{
 response.setContentType("text/html");
 InputStream in = request.getInputStream();
 OutputStream out   = response.getOutputStream();
 int contentLength  = request.getContentLength();
 byte[] bytes   = new byte[contentLength];
 int actualRead = 0;
 int bytesRead  = 0;
 
 while (bytesRead  contentLength) {
 actualRead = in.read(bytes, bytesRead, contentLength);
 bytesRead += actualRead;
 }
 out.write(bytes);
 }
 }
 
 
 

---
Joseph B. Ottinger   [EMAIL PROTECTED]
http://cupid.suninternet.com/~joeo  HOMES.COM Developer





Re: 1.2.9 bug: InputStream from request throwing an exception

2000-09-05 Thread Magnus Stenman

Hi,
this is not a bug. In your code, change the line:
 actualRead = in.read(bytes, bytesRead, contentLength);
to:
 actualRead = in.read(bytes, bytesRead, contentLength -
bytesRead);

Orion is throwing an IOB exception back at you per the InputStream
specification since the specified offset + length doesnt fit into the byte[]
supplied (from the API: "If off is negative, or len is negative, or off+len
is greater than the length of the array b, then an IndexOutOfBoundsException
is thrown."). We have extended the error message now so it will in your case
read (for a large file):
java.lang.IndexOutOfBoundsException: The supplied offset + length did not
fit into the supplied byte[] (offset + length = 2048 + 12590395 = 12592443
vs byte[].length = 12590395)

As for bug reporting Orion-Interest not meant for that, I'd recommend you to
use bugzilla (www.orionserver.com - bugzilla), that way others interested
in the bug can follow it/augment it too.

Hope it helps, have a nice day!

/Magnus Stenman, the Orion team

PS. Great that you supplied the source! That is always encouraged and will
make our job easer in hunting stuff down. Without source this would probably
have costed us a lot more timewise by bulletproofing (again) the read(...)
method. Reports that send a simple testcase (like this one) in the form of a
.war, .ear or .java naturally receive a higher priority than those without.



- Original Message -
From: "Scott Lawrence" [EMAIL PROTECTED]
To: "Orion-Interest" [EMAIL PROTECTED]
Sent: Tuesday, September 05, 2000 7:34 AM
Subject: 1.2.9 bug: InputStream from request throwing an exception


 Orion 1.2.9
 Windows 2000
 J2SE 1.3.0

 Bug: Underlying InputStream from request.getInputStream() throws an
 exception when the input stream should return more than 2048 bytes.

 Example: The following error occurs when running the JSP and servlet
below.
 The underlying input stream seems to throw and exception during
in.read(...)
 when trying to upload a file that's greater than 2048 (actually when the
 file + the extra multi encoding   2048).  I've tried this on Tomcat 3.2b
 and it works fine.  I've used similar code on older servers (not orion)
and
 didn't have this problem.  I'm writing this to the users group as well in
 case others are having problems with this.  If you work with file
uploading
 through forms, this will certainly hamper your progress.


 500 Internal Server Error
 java.lang.IndexOutOfBoundsException
 at com.evermind.server.http.ep.read(JAX)
 at InputStreamBug.doPost(InputStreamBug.java:21)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java)
 at com.evermind.server.http.du.rr(JAX)
 at com.evermind.server.http.du.forward(JAX)
 at com.evermind.server.http.d5.rx(JAX)
 at com.evermind.server.http.d5.rw(JAX)
 at com.evermind.util.f.run(JAX)

 InputStreamBug.jsp
 %@page contentType="text/html"%
 html
 headtitleInputStreamBug/title/head
 body
 FORM action='servlet/InputStreamBug' enctype='multipart/form-data'
 method='post'
 INPUT type='file' name='filename'BR
 INPUT type='submit' name='submit' value='Upload'
 /FORM
 /body
 /html


 InputStreamBug.java---
 import javax.servlet.*;
 import javax.servlet.http.*;
 import java.io.*;
 import java.util.*;

 public class InputStreamBug extends HttpServlet {
 /**
  * Reads the input stream and outputs the results to the output
stream.
  */
 public void doPost(HttpServletRequest request, HttpServletResponse
 response)
 throws IOException{
 response.setContentType("text/html");
 InputStream in = request.getInputStream();
 OutputStream out   = response.getOutputStream();
 int contentLength  = request.getContentLength();
 byte[] bytes   = new byte[contentLength];
 int actualRead = 0;
 int bytesRead  = 0;

 while (bytesRead  contentLength) {
 actualRead = in.read(bytes, bytesRead, contentLength);
 bytesRead += actualRead;
 }
 out.write(bytes);
 }
 }







RE: 1.2.9 bug: InputStream from request throwing an exception

2000-09-05 Thread Scott Lawrence

Sorry, I didn't see the Bugzilla link on the web site.  I knew there was a
better place for this but I couldn't find it.  I see it now.

The InputStream is to spec just as Magnus has said.  The funny thing is that
my code actually works in Tomcat and some other servers.  I suppose I'll
report the bug to the jakarta project.

Thanks for the added info in the message of the exception.  That should help
other poor souls in identifying the problem.





1.2.9 bug: InputStream from request throwing an exception

2000-09-04 Thread Scott Lawrence

Orion 1.2.9
Windows 2000
J2SE 1.3.0

Bug: Underlying InputStream from request.getInputStream() throws an
exception when the input stream should return more than 2048 bytes.

Example: The following error occurs when running the JSP and servlet below.
The underlying input stream seems to throw and exception during in.read(...)
when trying to upload a file that's greater than 2048 (actually when the
file + the extra multi encoding   2048).  I've tried this on Tomcat 3.2b
and it works fine.  I've used similar code on older servers (not orion) and
didn't have this problem.  I'm writing this to the users group as well in
case others are having problems with this.  If you work with file uploading
through forms, this will certainly hamper your progress.


500 Internal Server Error
java.lang.IndexOutOfBoundsException
at com.evermind.server.http.ep.read(JAX)
at InputStreamBug.doPost(InputStreamBug.java:21)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at com.evermind.server.http.du.rr(JAX)
at com.evermind.server.http.du.forward(JAX)
at com.evermind.server.http.d5.rx(JAX)
at com.evermind.server.http.d5.rw(JAX)
at com.evermind.util.f.run(JAX)

InputStreamBug.jsp
%@page contentType="text/html"%
html
headtitleInputStreamBug/title/head
body
FORM action='servlet/InputStreamBug' enctype='multipart/form-data'
method='post'
INPUT type='file' name='filename'BR
INPUT type='submit' name='submit' value='Upload'
/FORM
/body
/html


InputStreamBug.java---
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class InputStreamBug extends HttpServlet {
/**
 * Reads the input stream and outputs the results to the output stream.
 */
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws IOException{
response.setContentType("text/html");
InputStream in = request.getInputStream();
OutputStream out   = response.getOutputStream();
int contentLength  = request.getContentLength();
byte[] bytes   = new byte[contentLength];
int actualRead = 0;
int bytesRead  = 0;

while (bytesRead  contentLength) {
actualRead = in.read(bytes, bytesRead, contentLength);
bytesRead += actualRead;
}
out.write(bytes);
}
}