Changeset 7090:a2f5e25d6a28 in nginx


Ignore:
Timestamp:
08/10/17 19:21:23 (4 months ago)
Author:
Maxim Dounin <mdounin@…>
Branch:
default
Message:

Range filter: changed type for total length to off_t.

Total length of a response with multiple ranges can be larger than a size_t
variable can hold, so type changed to off_t. Previously, an incorrect
Content-Length was returned when requesting more than 4G of ranges from
a large enough file on a 32-bit system.

An additional size_t variable introduced to calculate size of the boundary
header buffer, as off_t is not needed here and will require type casts on
win32.

Reported by Shuxin Yang,
http://mailman.nginx.org/pipermail/nginx/2017-July/054384.html.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/http/modules/ngx_http_range_filter_module.c

    r7067 r7090  
    464464    ngx_http_range_filter_ctx_t *ctx)
    465465{
    466     size_t              len;
     466    off_t               len;
     467    size_t              size;
    467468    ngx_uint_t          i;
    468469    ngx_http_range_t   *range;
    469470    ngx_atomic_uint_t   boundary;
    470471
    471     len = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN
    472           + sizeof(CRLF "Content-Type: ") - 1
    473           + r->headers_out.content_type.len
    474           + sizeof(CRLF "Content-Range: bytes ") - 1;
     472    size = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN
     473           + sizeof(CRLF "Content-Type: ") - 1
     474           + r->headers_out.content_type.len
     475           + sizeof(CRLF "Content-Range: bytes ") - 1;
    475476
    476477    if (r->headers_out.content_type_len == r->headers_out.content_type.len
    477478        && r->headers_out.charset.len)
    478479    {
    479         len += sizeof("; charset=") - 1 + r->headers_out.charset.len;
    480     }
    481 
    482     ctx->boundary_header.data = ngx_pnalloc(r->pool, len);
     480        size += sizeof("; charset=") - 1 + r->headers_out.charset.len;
     481    }
     482
     483    ctx->boundary_header.data = ngx_pnalloc(r->pool, size);
    483484    if (ctx->boundary_header.data == NULL) {
    484485        return NGX_ERROR;
     
    570571
    571572        len += ctx->boundary_header.len + range[i].content_range.len
    572                                     + (size_t) (range[i].end - range[i].start);
     573                                             + (range[i].end - range[i].start);
    573574    }
    574575
Note: See TracChangeset for help on using the changeset viewer.