# HG changeset patch # User Maxim Dounin # Date 1217674993 -14400 # Node ID 48cdd1bfa48ee02622bf4398d1345b3208c61369 # Parent 47a21c299f1102ca740cdc54907c12b54546ba96 Correctly handle last ignored buffer. diff --git a/ngx_http_bytes_filter_module.c b/ngx_http_bytes_filter_module.c --- a/ngx_http_bytes_filter_module.c +++ b/ngx_http_bytes_filter_module.c @@ -253,6 +253,12 @@ ngx_http_bytes_header_filter(ngx_http_re end = r->headers_out.content_length_n - 1; } + if (start > end) { + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "bytes header filter: invalid range specification"); + return ngx_http_next_header_filter(r); + } + range->start = start; range->end = end + 1; len += range->end - range->start; @@ -261,7 +267,7 @@ ngx_http_bytes_header_filter(ngx_http_re default: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "bytes header filter: invalid range specification"); + "bytes header filter: invalid range specification"); return ngx_http_next_header_filter(r); } @@ -336,6 +342,34 @@ ngx_http_bytes_body_filter(ngx_http_requ size = ngx_buf_size(buf); + if (range->start > ctx->offset + size || range->end < ctx->offset) { + + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "bytes body filter: last buffer ignored"); + + buf->pos = buf->last; + + cl = ngx_alloc_chain_link(r->pool); + if (cl == NULL) { + return NGX_ERROR; + } + + b = ngx_calloc_buf(r->pool); + if (b == NULL) { + return NGX_ERROR; + } + + b->last_buf = 1; + + cl->buf = b; + cl->next = NULL; + + return ngx_http_next_body_filter(r, cl); + } + + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "bytes body filter: last buffer, %d", size); + if (buf->in_file) { if (range->start > ctx->offset) { buf->file_pos += range->start - ctx->offset;