You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ke...@apache.org on 2001/09/10 23:51:57 UTC

cvs commit: jakarta-tomcat-connectors/jk/native/common jk_ajp_common.c jk_ajp_common.h

keith       01/09/10 14:51:57

  Modified:    jk/native/common jk_ajp_common.c jk_ajp_common.h
  Log:
  Corner case for chunked encoding:  if the chunk sizes and
  buffers fell such that the buffer was nearly full and the
  chunk size digits were too numerous to fit in the remaining
  space, the remaining chunks would be tossed.  A simple
  solution is to not allow quite the entire buffer to be used
  in the chunked encoding case; pad it with a reasonable
  number of bytes.
  
  I chose 12 bytes because it allows for a chunk size of 2^40,
  assuming no transfer extensions.
  
  Reported by: David Schreibman <DS...@eTranslate.com>
  
  Revision  Changes    Path
  1.10      +18 -8     jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.c
  
  Index: jk_ajp_common.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- jk_ajp_common.c	2001/09/10 18:32:36	1.9
  +++ jk_ajp_common.c	2001/09/10 21:51:57	1.10
  @@ -687,21 +687,31 @@
                                         unsigned         len)
   {
       unsigned rdlen = 0;
  -
  -    if (s->is_chunked && s->no_more_chunks) {
  -	return 0;
  -    }
  +    unsigned padded_len = len;
   
  -    while(rdlen < len) {
  +    if (s->is_chunked && s->no_more_chunks) {
  +	return 0;
  +    }
  +    if (s->is_chunked) {
  +        /* Corner case: buf must be large enough to hold next
  +         * chunk size (if we're on or near a chunk border).
  +         * Pad the length to a reasonable value, otherwise the
  +         * read fails and the remaining chunks are tossed.
  +         */
  +        padded_len = (len < CHUNK_BUFFER_PAD) ?
  +                      len : len - CHUNK_BUFFER_PAD;
  +    }
  +
  +    while(rdlen < padded_len) {
           unsigned this_time = 0;
           if(!s->read(s, buf + rdlen, len - rdlen, &this_time)) {
               return -1;
           }
   
           if(0 == this_time) {
  -	    if (s->is_chunked) {
  -		s->no_more_chunks = 1; /* read no more */
  -	    }
  +	    if (s->is_chunked) {
  +		s->no_more_chunks = 1; /* read no more */
  +	    }
               break;
           }
           rdlen += this_time;
  
  
  
  1.7       +2 -1      jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.h
  
  Index: jk_ajp_common.h
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.h,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- jk_ajp_common.h	2001/08/27 15:33:04	1.6
  +++ jk_ajp_common.h	2001/09/10 21:51:57	1.7
  @@ -204,6 +204,7 @@
   
   #define AJP_HEADER_LEN            (4)
   #define AJP_HEADER_SZ_LEN         (2)
  +#define CHUNK_BUFFER_PAD          (12)
   
   
   struct jk_res_data {