1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Fix use of "unsafeBytes" leading to offset errors and regen parser.

This commit is contained in:
Charles Oliver Nutter 2011-11-22 16:23:34 -06:00
parent 6f26608a19
commit 0e316b2c20
2 changed files with 29 additions and 25 deletions

View file

@ -121,7 +121,9 @@ public class Http11Parser {
p = off; p = off;
pe = len; pe = len;
byte[] data = buffer.unsafeBytes(); // get a copy of the bytes, since it may not start at 0
// FIXME: figure out how to just use the bytes in-place
byte[] data = buffer.bytes();
parser.buffer = buffer; parser.buffer = buffer;
%% write exec; %% write exec;

View file

@ -1,5 +1,5 @@
// line 1 "ext/http11/http11_parser.java.rl" // line 1 "ext/puma_http11/http11_parser.java.rl"
package org.jruby.puma; package org.jruby.puma;
import org.jruby.util.ByteList; import org.jruby.util.ByteList;
@ -9,12 +9,12 @@ public class Http11Parser {
/** Machine **/ /** Machine **/
// line 65 "ext/http11/http11_parser.java.rl" // line 65 "ext/puma_http11/http11_parser.java.rl"
/** Data **/ /** Data **/
// line 18 "ext/http11/org/jruby/mongrel/Http11Parser.java" // line 18 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
private static byte[] init__http_parser_actions_0() private static byte[] init__http_parser_actions_0()
{ {
return new byte [] { return new byte [] {
@ -200,7 +200,7 @@ static final int http_parser_error = 0;
static final int http_parser_en_main = 1; static final int http_parser_en_main = 1;
// line 69 "ext/http11/http11_parser.java.rl" // line 69 "ext/puma_http11/http11_parser.java.rl"
public static interface ElementCB { public static interface ElementCB {
public void call(Object data, int at, int length); public void call(Object data, int at, int length);
@ -236,12 +236,12 @@ static final int http_parser_en_main = 1;
cs = 0; cs = 0;
// line 240 "ext/http11/org/jruby/mongrel/Http11Parser.java" // line 240 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
{ {
cs = http_parser_start; cs = http_parser_start;
} }
// line 104 "ext/http11/http11_parser.java.rl" // line 104 "ext/puma_http11/http11_parser.java.rl"
body_start = 0; body_start = 0;
content_len = 0; content_len = 0;
@ -262,11 +262,13 @@ static final int http_parser_en_main = 1;
p = off; p = off;
pe = len; pe = len;
byte[] data = buffer.unsafeBytes(); // get a copy of the bytes, since it may not start at 0
// FIXME: figure out how to just use the bytes in-place
byte[] data = buffer.bytes();
parser.buffer = buffer; parser.buffer = buffer;
// line 270 "ext/http11/org/jruby/mongrel/Http11Parser.java" // line 272 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
{ {
int _klen; int _klen;
int _trans = 0; int _trans = 0;
@ -347,29 +349,29 @@ case 1:
switch ( _http_parser_actions[_acts++] ) switch ( _http_parser_actions[_acts++] )
{ {
case 0: case 0:
// line 13 "ext/http11/http11_parser.java.rl" // line 13 "ext/puma_http11/http11_parser.java.rl"
{parser.mark = p; } {parser.mark = p; }
break; break;
case 1: case 1:
// line 15 "ext/http11/http11_parser.java.rl" // line 15 "ext/puma_http11/http11_parser.java.rl"
{ parser.field_start = p; } { parser.field_start = p; }
break; break;
case 2: case 2:
// line 16 "ext/http11/http11_parser.java.rl" // line 16 "ext/puma_http11/http11_parser.java.rl"
{ /* FIXME stub */ } { /* FIXME stub */ }
break; break;
case 3: case 3:
// line 17 "ext/http11/http11_parser.java.rl" // line 17 "ext/puma_http11/http11_parser.java.rl"
{ {
parser.field_len = p-parser.field_start; parser.field_len = p-parser.field_start;
} }
break; break;
case 4: case 4:
// line 21 "ext/http11/http11_parser.java.rl" // line 21 "ext/puma_http11/http11_parser.java.rl"
{ parser.mark = p; } { parser.mark = p; }
break; break;
case 5: case 5:
// line 22 "ext/http11/http11_parser.java.rl" // line 22 "ext/puma_http11/http11_parser.java.rl"
{ {
if(parser.http_field != null) { if(parser.http_field != null) {
parser.http_field.call(parser.data, parser.field_start, parser.field_len, parser.mark, p-parser.mark); parser.http_field.call(parser.data, parser.field_start, parser.field_len, parser.mark, p-parser.mark);
@ -377,53 +379,53 @@ case 1:
} }
break; break;
case 6: case 6:
// line 27 "ext/http11/http11_parser.java.rl" // line 27 "ext/puma_http11/http11_parser.java.rl"
{ {
if(parser.request_method != null) if(parser.request_method != null)
parser.request_method.call(parser.data, parser.mark, p-parser.mark); parser.request_method.call(parser.data, parser.mark, p-parser.mark);
} }
break; break;
case 7: case 7:
// line 31 "ext/http11/http11_parser.java.rl" // line 31 "ext/puma_http11/http11_parser.java.rl"
{ {
if(parser.request_uri != null) if(parser.request_uri != null)
parser.request_uri.call(parser.data, parser.mark, p-parser.mark); parser.request_uri.call(parser.data, parser.mark, p-parser.mark);
} }
break; break;
case 8: case 8:
// line 35 "ext/http11/http11_parser.java.rl" // line 35 "ext/puma_http11/http11_parser.java.rl"
{ {
if(parser.fragment != null) if(parser.fragment != null)
parser.fragment.call(parser.data, parser.mark, p-parser.mark); parser.fragment.call(parser.data, parser.mark, p-parser.mark);
} }
break; break;
case 9: case 9:
// line 40 "ext/http11/http11_parser.java.rl" // line 40 "ext/puma_http11/http11_parser.java.rl"
{parser.query_start = p; } {parser.query_start = p; }
break; break;
case 10: case 10:
// line 41 "ext/http11/http11_parser.java.rl" // line 41 "ext/puma_http11/http11_parser.java.rl"
{ {
if(parser.query_string != null) if(parser.query_string != null)
parser.query_string.call(parser.data, parser.query_start, p-parser.query_start); parser.query_string.call(parser.data, parser.query_start, p-parser.query_start);
} }
break; break;
case 11: case 11:
// line 46 "ext/http11/http11_parser.java.rl" // line 46 "ext/puma_http11/http11_parser.java.rl"
{ {
if(parser.http_version != null) if(parser.http_version != null)
parser.http_version.call(parser.data, parser.mark, p-parser.mark); parser.http_version.call(parser.data, parser.mark, p-parser.mark);
} }
break; break;
case 12: case 12:
// line 51 "ext/http11/http11_parser.java.rl" // line 51 "ext/puma_http11/http11_parser.java.rl"
{ {
if(parser.request_path != null) if(parser.request_path != null)
parser.request_path.call(parser.data, parser.mark, p-parser.mark); parser.request_path.call(parser.data, parser.mark, p-parser.mark);
} }
break; break;
case 13: case 13:
// line 56 "ext/http11/http11_parser.java.rl" // line 56 "ext/puma_http11/http11_parser.java.rl"
{ {
parser.body_start = p + 1; parser.body_start = p + 1;
if(parser.header_done != null) if(parser.header_done != null)
@ -431,7 +433,7 @@ case 1:
{ p += 1; _goto_targ = 5; if (true) continue _goto;} { p += 1; _goto_targ = 5; if (true) continue _goto;}
} }
break; break;
// line 435 "ext/http11/org/jruby/mongrel/Http11Parser.java" // line 437 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
} }
} }
} }
@ -451,7 +453,7 @@ case 5:
break; } break; }
} }
// line 128 "ext/http11/http11_parser.java.rl" // line 130 "ext/puma_http11/http11_parser.java.rl"
parser.cs = cs; parser.cs = cs;
parser.nread += (p - off); parser.nread += (p - off);