mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 17:52:38 +08:00
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.
This commit is contained in:
parent
dd5ab4a11f
commit
008e9caa2a
@ -463,12 +463,13 @@ static ngx_int_t
|
|||||||
ngx_http_range_multipart_header(ngx_http_request_t *r,
|
ngx_http_range_multipart_header(ngx_http_request_t *r,
|
||||||
ngx_http_range_filter_ctx_t *ctx)
|
ngx_http_range_filter_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
size_t len;
|
off_t len;
|
||||||
|
size_t size;
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
ngx_http_range_t *range;
|
ngx_http_range_t *range;
|
||||||
ngx_atomic_uint_t boundary;
|
ngx_atomic_uint_t boundary;
|
||||||
|
|
||||||
len = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN
|
size = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN
|
||||||
+ sizeof(CRLF "Content-Type: ") - 1
|
+ sizeof(CRLF "Content-Type: ") - 1
|
||||||
+ r->headers_out.content_type.len
|
+ r->headers_out.content_type.len
|
||||||
+ sizeof(CRLF "Content-Range: bytes ") - 1;
|
+ sizeof(CRLF "Content-Range: bytes ") - 1;
|
||||||
@ -476,10 +477,10 @@ ngx_http_range_multipart_header(ngx_http_request_t *r,
|
|||||||
if (r->headers_out.content_type_len == r->headers_out.content_type.len
|
if (r->headers_out.content_type_len == r->headers_out.content_type.len
|
||||||
&& r->headers_out.charset.len)
|
&& r->headers_out.charset.len)
|
||||||
{
|
{
|
||||||
len += sizeof("; charset=") - 1 + r->headers_out.charset.len;
|
size += sizeof("; charset=") - 1 + r->headers_out.charset.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->boundary_header.data = ngx_pnalloc(r->pool, len);
|
ctx->boundary_header.data = ngx_pnalloc(r->pool, size);
|
||||||
if (ctx->boundary_header.data == NULL) {
|
if (ctx->boundary_header.data == NULL) {
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
@ -569,7 +570,7 @@ ngx_http_range_multipart_header(ngx_http_request_t *r,
|
|||||||
- range[i].content_range.data;
|
- range[i].content_range.data;
|
||||||
|
|
||||||
len += ctx->boundary_header.len + range[i].content_range.len
|
len += ctx->boundary_header.len + range[i].content_range.len
|
||||||
+ (size_t) (range[i].end - range[i].start);
|
+ (range[i].end - range[i].start);
|
||||||
}
|
}
|
||||||
|
|
||||||
r->headers_out.content_length_n = len;
|
r->headers_out.content_length_n = len;
|
||||||
|
Loading…
Reference in New Issue
Block a user