@@ -20,7 +20,7 @@ public class HTTPParser {
2020 int flags ; // TODO
2121
2222 int nread ;
23- int content_length ;
23+ long content_length ;
2424
2525 int p_start ; // updated each call to execute to indicate where the buffer was before we began calling it.
2626
@@ -1125,13 +1125,13 @@ public int execute(ParserSettings settings, ByteBuffer data) {
11251125return error (settings , "Content-Length not numeric" , data );
11261126 }
11271127
1128- int t = content_length ;
1128+ long t = content_length ;
11291129 t *= 10 ;
1130- t += (int )ch - 0x30 ;
1130+ t += (long )ch - 0x30 ;
11311131
11321132 /* Overflow? */
1133- //TODO Not sure how to check
1134- if (t < content_length || t == - 1 ) { //ULLONG_MAX ??
1133+ // t will wrap and become negative ...
1134+ if (t < content_length ) {
11351135 return error (settings , "Invalid content length" , data );
11361136 }
11371137 content_length = t ;
@@ -1379,11 +1379,11 @@ public int execute(ParserSettings settings, ByteBuffer data) {
13791379 }
13801380 return error (settings , "invalid hex char in chunk content length" , data );
13811381 }
1382- int t = content_length ;
1382+ long t = content_length ;
13831383
13841384 t *= 16 ;
13851385 t += c ;
1386- if (t < content_length || t == - 1 ){
1386+ if (t < content_length ){
13871387 return error (settings , "invalid content length" , data );
13881388 }
13891389 content_length = t ;
@@ -1639,6 +1639,9 @@ final int min (int a, int b) {
16391639 return a < b ? a : b ;
16401640 }
16411641
1642+ final int min (int a , long b ) {
1643+ return a < b ? a : (int )b ;
1644+ }
16421645 /* probably not the best place to hide this ... */
16431646 public boolean HTTP_PARSER_STRICT ;
16441647 State new_message () {
0 commit comments