You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Johannes Lietz <jo...@antwerpes.de> on 2003/05/21 20:28:01 UTC

mod_jk + mod_jk2 Connector Errors

I got strange problems with the apache-tomcat connector on my server:

In general my setup seems to work, but maybe 5-10% of the requests to 
the apache server show some binary output which I cannot idenitify, 
followed by the regular HTTP response header ("HTTP/1.1 200 OK" etc.), 
followed by the regular content of the page.
The results are broken pages and broken images (some of my images are 
actually servlet output).

I'm using Apache 2.0.45 and Tomcat 4.1.24 on Linux, and I tried both 
mod_jk and mod_jk2. The result the same with all configurations.

Tomcat as standalone webserver works perfectly, and Apache deliveres 
the static content from my project without errors.


Any idea anybody?

Thanks in advance,
Johannes


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: mod_jk + mod_jk2 Connector Errors

Posted by Johannes Lietz <jo...@antwerpes.de>.
Here it is:

   while  (numRead  >=  0)
   {
     buffer.rewind();
     numRead = channel.read(buffer);
     buffer.rewind();
     if (numRead  ==  BUFFERSIZE)
     {
       buffer.get(bytes);
       out.write(bytes);
     }
     else
     {
       byte[] lastBytes = new byte[numRead];
       buffer.get(lastBytes);
       out.write(lastBytes);
       break;
     }
   }

I'm not shure: is this a potential security issue in mod_jk?


On Freitag, Mai 23, 2003, at 03:45  Uhr, John Turner wrote:

>
> So what was the fix?
>
> I do mine like this and don't have any problems:
>
>        java.io.OutputStream o = response.getOutputStream();
>        java.io.FileInputStream is = new 
> java.io.FileInputStream(outputDir + "/" + srcFile);
>        java.io.File oFile = new java.io.File(outputDir + "/" + 
> srcFile);
>
>        response.setContentType("image/gif");
>        response.setContentLength((int)oFile.length());
>
>        byte[] buf = new byte[32 * 1024]; // 32k buffer
>
>        int nRead = 0;
>        while( (nRead=is.read(buf)) != -1 ) {
>            o.write(buf, 0, nRead);
>        }
>
>        o.flush();
>        o.close();
>
> John
>
> On Fri, 23 May 2003 15:32:06 +0200, Johannes Lietz 
> <jo...@antwerpes.de> wrote:
>
>> Finally I fixed this!
>>
>> What happened?
>>
>> I have a servlet streaming files from the server's harddrive to the 
>> browser:
>>
>>
>> public void doGet(HttpServletRequest request, HttpServletResponse  
>> response)
>> throws ServletException, IOException
>> {
>> ...
>>
>> FileChannel channel = new FileInputStream(file).getChannel();
>>
>> response.setContentLength((int) channel.size());
>>
>> ByteBuffer buffer = ByteBuffer.allocateDirect(BUFFERSIZE);
>>
>> int numRead = 0;
>> byte[] bytes = new byte[BUFFERSIZE];
>>
>> ServletOutputStream  out = response.getOutputStream();
>>
>> while (numRead >= 0)
>> {
>> buffer.rewind();
>> numRead = channel.read(buffer);
>> buffer.rewind();
>> buffer.get(bytes);
>> out.write(bytes);
>> }
>> out.close();
>> channel.close();
>> }
>>
>>
>> In this way, more bytes than indicated by response.setContentLength() 
>> are written to the ServletOutputStream.
>>
>> This is not a problem for Tomcat as standalone server, but for both 
>> mod_jk and mod_jk2.
>> Both will get some kind of buffer overflow and randomly repeat the 
>> surplus bytes, even across different requests.
>>
>> Maybe this should be fixed in mod_jk2?
>>
>> - Johannes
>>
>>
>> On Mittwoch, Mai 21, 2003, at 08:28  Uhr, Johannes Lietz wrote:
>>
>>> I got strange problems with the apache-tomcat connector on my server:
>>>
>>> In general my setup seems to work, but maybe 5-10% of the requests 
>>> to the apache server show some binary output which I cannot 
>>> idenitify, followed by the regular HTTP response header ("HTTP/1.1 
>>> 200 OK" etc.), followed by the regular content of the page.
>>> The results are broken pages and broken images (some of my images 
>>> are actually servlet output).
>>>
>>> I'm using Apache 2.0.45 and Tomcat 4.1.24 on Linux, and I tried both 
>>> mod_jk and mod_jk2. The result the same with all configurations.
>>>
>>> Tomcat as standalone webserver works perfectly, and Apache deliveres 
>>> the static content from my project without errors.
>>>
>>>
>>> Any idea anybody?
>>>
>>> Thanks in advance,
>>> Johannes
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>
>
>
> -- 
> Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: mod_jk + mod_jk2 Connector Errors

Posted by John Turner <to...@johnturner.com>.
So what was the fix?

I do mine like this and don't have any problems:

        java.io.OutputStream o = response.getOutputStream();
        java.io.FileInputStream is = new java.io.FileInputStream(outputDir 
+ "/" + srcFile);
        java.io.File oFile = new java.io.File(outputDir + "/" + srcFile);

        response.setContentType("image/gif");
        response.setContentLength((int)oFile.length());

        byte[] buf = new byte[32 * 1024]; // 32k buffer

        int nRead = 0;
        while( (nRead=is.read(buf)) != -1 ) {
            o.write(buf, 0, nRead);
        }

        o.flush();
        o.close();

John

On Fri, 23 May 2003 15:32:06 +0200, Johannes Lietz 
<jo...@antwerpes.de> wrote:

> Finally I fixed this!
>
> What happened?
>
> I have a servlet streaming files from the server's harddrive to the 
> browser:
>
>
> public void doGet(HttpServletRequest request, HttpServletResponse  
> response)
> throws ServletException, IOException
> {
> ...
>
> FileChannel channel = new FileInputStream(file).getChannel();
>
> response.setContentLength((int) channel.size());
>
> ByteBuffer buffer = ByteBuffer.allocateDirect(BUFFERSIZE);
>
> int numRead = 0;
> byte[] bytes = new byte[BUFFERSIZE];
>
> ServletOutputStream  out = response.getOutputStream();
>
> while (numRead >= 0)
> {
> buffer.rewind();
> numRead = channel.read(buffer);
> buffer.rewind();
> buffer.get(bytes);
> out.write(bytes);
> }
> out.close();
> channel.close();
> }
>
>
> In this way, more bytes than indicated by response.setContentLength() are 
> written to the ServletOutputStream.
>
> This is not a problem for Tomcat as standalone server, but for both 
> mod_jk and mod_jk2.
> Both will get some kind of buffer overflow and randomly repeat the 
> surplus bytes, even across different requests.
>
> Maybe this should be fixed in mod_jk2?
>
> - Johannes
>
>
> On Mittwoch, Mai 21, 2003, at 08:28  Uhr, Johannes Lietz wrote:
>
>> I got strange problems with the apache-tomcat connector on my server:
>>
>> In general my setup seems to work, but maybe 5-10% of the requests to 
>> the apache server show some binary output which I cannot idenitify, 
>> followed by the regular HTTP response header ("HTTP/1.1 200 OK" etc.), 
>> followed by the regular content of the page.
>> The results are broken pages and broken images (some of my images are 
>> actually servlet output).
>>
>> I'm using Apache 2.0.45 and Tomcat 4.1.24 on Linux, and I tried both 
>> mod_jk and mod_jk2. The result the same with all configurations.
>>
>> Tomcat as standalone webserver works perfectly, and Apache deliveres the 
>> static content from my project without errors.
>>
>>
>> Any idea anybody?
>>
>> Thanks in advance,
>> Johannes
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: mod_jk + mod_jk2 Connector Errors

Posted by Johannes Lietz <jo...@antwerpes.de>.
Finally I fixed this!

What happened?

I have a servlet streaming files from the server's harddrive to the 
browser:


public void doGet(HttpServletRequest request, HttpServletResponse  
response)
   throws ServletException, IOException
{
   ...

   FileChannel channel = new FileInputStream(file).getChannel();

   response.setContentLength((int) channel.size());

   ByteBuffer buffer = ByteBuffer.allocateDirect(BUFFERSIZE);

   int numRead = 0;
   byte[] bytes = new byte[BUFFERSIZE];

   ServletOutputStream  out = response.getOutputStream();

   while (numRead >= 0)
   {
     buffer.rewind();
     numRead = channel.read(buffer);
     buffer.rewind();
     buffer.get(bytes);
     out.write(bytes);
   }
   out.close();
   channel.close();
}


In this way, more bytes than indicated by response.setContentLength() 
are written to the ServletOutputStream.

This is not a problem for Tomcat as standalone server, but for both 
mod_jk and mod_jk2.
Both will get some kind of buffer overflow and randomly repeat the 
surplus bytes, even across different requests.

Maybe this should be fixed in mod_jk2?

- Johannes


On Mittwoch, Mai 21, 2003, at 08:28  Uhr, Johannes Lietz wrote:

> I got strange problems with the apache-tomcat connector on my server:
>
> In general my setup seems to work, but maybe 5-10% of the requests to 
> the apache server show some binary output which I cannot idenitify, 
> followed by the regular HTTP response header ("HTTP/1.1 200 OK" etc.), 
> followed by the regular content of the page.
> The results are broken pages and broken images (some of my images are 
> actually servlet output).
>
> I'm using Apache 2.0.45 and Tomcat 4.1.24 on Linux, and I tried both 
> mod_jk and mod_jk2. The result the same with all configurations.
>
> Tomcat as standalone webserver works perfectly, and Apache deliveres 
> the static content from my project without errors.
>
>
> Any idea anybody?
>
> Thanks in advance,
> Johannes
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org