# HG changeset patch # User Ruslan Ermilov # Date 1426541187 -10800 # Node ID e370c5fdf4c8edc2e8d33d7170c1b1cc74a2ecb6 # Parent 9653092a79fd8bf27e78e0e1e4527501bf77c7fa Overflow detection in ngx_http_parse_chunked(). diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c --- a/src/http/ngx_http_parse.c +++ b/src/http/ngx_http_parse.c @@ -2155,6 +2155,10 @@ ngx_http_parse_chunked(ngx_http_request_ goto invalid; case sw_chunk_size: + if (ctx->size > NGX_MAX_OFF_T_VALUE / 16) { + goto invalid; + } + if (ch >= '0' && ch <= '9') { ctx->size = ctx->size * 16 + (ch - '0'); break; @@ -2304,6 +2308,10 @@ data: ctx->state = state; b->pos = pos; + if (ctx->size > NGX_MAX_OFF_T_VALUE - 5) { + goto invalid; + } + switch (state) { case sw_chunk_start: @@ -2340,10 +2348,6 @@ data: } - if (ctx->size < 0 || ctx->length < 0) { - goto invalid; - } - return rc; done: