Mantis - Resin
Viewing Issue Advanced Details
5807 minor always 10-01-14 17:24 10-01-14 17:24
nam  
nam  
normal  
closed 4.0.41  
fixed  
none    
none  
0005807: AbstractHttpResponse.setHeader(-1) throws IllegalArgumentException
(rep by stegard)

This works fine:
  response.setContentLength(-1);

However, we are encountering a Resin exception when the following is called:
  response.setHeader("Content-Length", "-1");

(IllegalArgumentException with message "-1 is an invalid content-length".)

Looks like AbstractHttpResponse#parseLong has an error in it with numbers prefixed with either "+" or "-".

Propose the following patch (Resin 4.0.41):

--- AbstractHttpResponse.java.orig 2014-10-01 22:47:03.133607270 +0200
+++ AbstractHttpResponse.java 2014-10-01 22:47:30.241607757 +0200
@@ -572,11 +572,11 @@
       sign = -1;
       
       if (i < length)
- ch = string.charAt(i++);
+ ch = string.charAt(++i);
     }
     else if (ch == '+') {
       if (i < length)
- ch = string.charAt(i++);
+ ch = string.charAt(++i);
     }
     
     if (! ('0' <= ch && ch <= '9')) {


----------------------------------------------------


Added checks to avoid going out of bounds on invalid number input:

--- AbstractHttpResponse.java.orig 2014-10-01 22:47:03.133607270 +0200
+++ AbstractHttpResponse.java 2014-10-01 23:06:58.209628739 +0200
@@ -571,12 +571,12 @@
     if (ch == '-') {
       sign = -1;
       
- if (i < length)
- ch = string.charAt(i++);
+ if (i < length-1)
+ ch = string.charAt(++i);
     }
     else if (ch == '+') {
- if (i < length)
- ch = string.charAt(i++);
+ if (i < length-1)
+ ch = string.charAt(++i);
     }
     
     if (! ('0' <= ch && ch <= '9')) {

Notes
(0006533)
nam   
10-01-14 17:24   
server/05ac

Fixed for 4.0.42.