Skip to content

Commit

Permalink
Fix bad pointer arithmetic
Browse files Browse the repository at this point in the history
The bad arithmetic didn't result in wrong or insecure behavior
(there were no out-of-bound accesses and forward progress was
still being made because of the outer loop) but it did regress
the performance of header field parsing rather massively.

Taking the test suite as an example: the inner fast path loop
was skipped over 4.4 million times, falling back to the outer
slow path loop. After this commit that only happens about
2,000 times - a 2,200-fold reduction.

Fixes: nodejs#473
PR-URL: nodejs#474
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
  • Loading branch information
bnoordhuis committed Apr 16, 2019
1 parent b6866a7 commit c7d4925
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1257,9 +1257,9 @@ size_t http_parser_execute (http_parser *parser,

switch (parser->header_state) {
case h_general: {
size_t limit = data + len - p;
limit = MIN(limit, max_header_size);
while (p+1 < data + limit && TOKEN(p[1])) {
size_t left = data + len - p;
const char* pe = p + MIN(left, max_header_size);
while (p+1 < pe && TOKEN(p[1])) {
p++;
}
break;
Expand Down

0 comments on commit c7d4925

Please sign in to comment.