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:43:36 UTC

cvs commit: jakarta-tomcat/src/native/mod_jk/common jk_ajp13_worker.c

keith       01/09/10 14:43:36

  Modified:    src/native/mod_jk/common jk_ajp13_worker.c
  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.12      +14 -3     jakarta-tomcat/src/native/mod_jk/common/jk_ajp13_worker.c
  
  Index: jk_ajp13_worker.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/native/mod_jk/common/jk_ajp13_worker.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- jk_ajp13_worker.c	2001/09/01 01:53:25	1.11
  +++ jk_ajp13_worker.c	2001/09/10 21:43:36	1.12
  @@ -79,6 +79,7 @@
   #define MAX_SEND_BODY_SZ        (DEF_BUFFER_SZ - 6)
   #define AJP13_HEADER_LEN	(4)
   #define AJP13_HEADER_SZ_LEN	(2)
  +#define CHUNK_BUFFER_PAD        (12)
   
   struct ajp13_operation;
   typedef struct ajp13_operation ajp13_operation_t;
  @@ -262,13 +263,23 @@
                                     unsigned char *buf, 
                                     unsigned len)
   {
  -    unsigned rdlen = 0;
  -
  +    unsigned rdlen = 0;
  +    unsigned padded_len = 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 < len) {
  +    while(rdlen < padded_len) {
           unsigned this_time = 0;
           if(!s->read(s, buf + rdlen, len - rdlen, &this_time)) {
               return -1;