tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf Ascii.java ByteChunk.java MessageBytes.java
Date Thu, 12 Aug 2004 21:46:41 GMT
markt       2004/08/12 14:46:41

  Modified:    coyote/src/java/org/apache/coyote Request.java
               http11/src/java/org/apache/coyote/http11
                        Http11Processor.java
               http11/src/java/org/apache/coyote/http11/filters
                        IdentityInputFilter.java
               util/java/org/apache/tomcat/util/buf Ascii.java
                        ByteChunk.java MessageBytes.java
  Log:
  Fix bug 30152. Support content-length greater than Integer.MAX_VALUE.
   - Limit is now Long.MAX_VALUE
   - Only tested in simulation, not with a POST bigger than Integer.MAX_VALUE
  
  Revision  Changes    Path
  1.30      +11 -3     jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Request.java
  
  Index: Request.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Request.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- Request.java	12 Aug 2004 19:48:05 -0000	1.29
  +++ Request.java	12 Aug 2004 21:46:41 -0000	1.30
  @@ -134,7 +134,7 @@
       /**
        * HTTP specific fields. (remove them ?)
        */
  -    private int contentLength = -1;
  +    private long contentLength = -1;
       private MessageBytes contentTypeMB = null;
       private String charEncoding = null;
       private Cookies cookies = new Cookies(headers);
  @@ -298,14 +298,22 @@
   
   
       public int getContentLength() {
  +        long length = getContentLengthLong();
  +
  +        if (length < Integer.MAX_VALUE) {
  +            return (int) length;
  +        }
  +        return -1;
  +    }
  +
  +    public long getContentLengthLong() {
           if( contentLength > -1 ) return contentLength;
   
           MessageBytes clB = headers.getValue("content-length");
  -        contentLength = (clB == null || clB.isNull()) ? -1 : clB.getInt();
  +        contentLength = (clB == null || clB.isNull()) ? -1 : clB.getLong();
   
           return contentLength;
       }
  -
   
       public String getContentType() {
           contentType();
  
  
  
  1.103     +1 -1      jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java
  
  Index: Http11Processor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java,v
  retrieving revision 1.102
  retrieving revision 1.103
  diff -u -r1.102 -r1.103
  --- Http11Processor.java	28 Jul 2004 18:52:17 -0000	1.102
  +++ Http11Processor.java	12 Aug 2004 21:46:41 -0000	1.103
  @@ -1196,7 +1196,7 @@
           InputFilter[] inputFilters = inputBuffer.getFilters();
   
           // Parse content-length header
  -        int contentLength = request.getContentLength();
  +        long contentLength = request.getContentLengthLong();
           if (contentLength >= 0) {
               inputBuffer.addActiveFilter
                   (inputFilters[Constants.IDENTITY_FILTER]);
  
  
  
  1.12      +1 -1      jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters/IdentityInputFilter.java
  
  Index: IdentityInputFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters/IdentityInputFilter.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- IdentityInputFilter.java	24 Feb 2004 08:50:55 -0000	1.11
  +++ IdentityInputFilter.java	12 Aug 2004 21:46:41 -0000	1.12
  @@ -144,7 +144,7 @@
        * Read the content length from the request.
        */
       public void setRequest(Request request) {
  -        contentLength = request.getContentLength();
  +        contentLength = request.getContentLengthLong();
           remaining = contentLength;
       }
   
  
  
  
  1.4       +65 -0     jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/Ascii.java
  
  Index: Ascii.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/Ascii.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Ascii.java	12 Aug 2004 19:48:06 -0000	1.3
  +++ Ascii.java	12 Aug 2004 21:46:41 -0000	1.4
  @@ -178,4 +178,69 @@
           return n;
       }
   
  +    /**
  +     * Parses an unsigned long from the specified subarray of bytes.
  +     * @param b the bytes to parse
  +     * @param off the start offset of the bytes
  +     * @param len the length of the bytes
  +     * @exception NumberFormatException if the long format was invalid
  +     */
  +    public static long parseLong(byte[] b, int off, int len)
  +        throws NumberFormatException
  +    {
  +        int c;
  +
  +        if (b == null || len <= 0 || !isDigit(c = b[off++])) {
  +            throw new NumberFormatException();
  +        }
  +
  +        long n = c - '0';
  +        long m;
  +        
  +        while (--len > 0) {
  +            if (!isDigit(c = b[off++])) {
  +                throw new NumberFormatException();
  +            }
  +            m = n * 10 + c - '0';
  +
  +            if (m < n) {
  +                // Overflow
  +                throw new NumberFormatException();
  +            } else {
  +                n = m;
  +            }
  +        }
  +
  +        return n;
  +    }
  +
  +    public static long parseLong(char[] b, int off, int len)
  +        throws NumberFormatException
  +    {
  +        int c;
  +
  +        if (b == null || len <= 0 || !isDigit(c = b[off++])) {
  +            throw new NumberFormatException();
  +        }
  +
  +        long n = c - '0';
  +        long m;
  +
  +        while (--len > 0) {
  +            if (!isDigit(c = b[off++])) {
  +                throw new NumberFormatException();
  +            }
  +            m = n * 10 + c - '0';
  +
  +            if (m < n) {
  +                // Overflow
  +                throw new NumberFormatException();
  +            } else {
  +                n = m;
  +            }
  +        }
  +
  +        return n;
  +    }
  +
   }
  
  
  
  1.20      +5 -0      jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/ByteChunk.java
  
  Index: ByteChunk.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/ByteChunk.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ByteChunk.java	8 Mar 2004 23:46:37 -0000	1.19
  +++ ByteChunk.java	12 Aug 2004 21:46:41 -0000	1.20
  @@ -477,6 +477,11 @@
   	return Ascii.parseInt(buff, start,end-start);
       }
   
  +    public long getLong() {
  +        return Ascii.parseLong(buff, start,end-start);
  +    }
  +
  +
       // -------------------- equals --------------------
   
       /**
  
  
  
  1.16      +23 -1     jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/MessageBytes.java
  
  Index: MessageBytes.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/MessageBytes.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- MessageBytes.java	15 Jul 2004 14:35:39 -0000	1.15
  +++ MessageBytes.java	12 Aug 2004 21:46:41 -0000	1.16
  @@ -510,11 +510,13 @@
       }
   
       // -------------------- Deprecated code --------------------
  -    // efficient int and date
  +    // efficient int, long and date
       // XXX used only for headers - shouldn't be
       // stored here.
       private int intValue;
       private boolean hasIntValue=false;
  +    private long longValue;
  +    private boolean hasLongValue=false;
       private Date dateValue;
       private boolean hasDateValue=false;
       
  @@ -622,6 +624,26 @@
   	hasIntValue=true;
   	return intValue;
       }
  +
  +    // Used for headers conversion
  +    /** Convert the buffer to an long, cache the value
  +     */ 
  +    public long getLong() {
  +        if( hasLongValue )
  +            return longValue;
  +        
  +        switch (type) {
  +        case T_BYTES:
  +            longValue=byteC.getLong();
  +            break;
  +        default:
  +            longValue=Long.parseLong(toString());
  +        }
  +
  +        hasLongValue=true;
  +        return longValue;
  +
  +     }
   
       // -------------------- Future may be different --------------------
       
  
  
  

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


Mime
View raw message