# HG changeset patch # User Maxim Dounin <mdou...@mdounin.ru> # Date 1748666373 -10800 # Sat May 31 07:39:33 2025 +0300 # Node ID 41e7de4b8d3918a501dc95c8b0e706703675fc92 # Parent 1ce7a2381e6a880636779800499a0bf99ca7bd6e Postpone filter: fixed incorrect content length check.
The code in ngx_http_postpone_filter_in_memory() used to assign r->headers_out.content_length_n to a size_t variable before comparison, which can lead to incorrect results on 32-bit platforms. Fix is to compare r->headers_out.content_length_n before conversion to size_t. Found with MSVC with C4244 warnings (conversion from 'type1' to 'type2', possible loss of data) enabled. diff --git a/src/http/ngx_http_postpone_filter_module.c b/src/http/ngx_http_postpone_filter_module.c --- a/src/http/ngx_http_postpone_filter_module.c +++ b/src/http/ngx_http_postpone_filter_module.c @@ -194,14 +194,18 @@ ngx_http_postpone_filter_in_memory(ngx_h clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); if (r->headers_out.content_length_n != -1) { - len = r->headers_out.content_length_n; - if (len > clcf->subrequest_output_buffer_size) { + if (r->headers_out.content_length_n + > (off_t) clcf->subrequest_output_buffer_size) + { ngx_log_error(NGX_LOG_ERR, c->log, 0, - "too big subrequest response: %uz", len); + "too big subrequest response: %O", + r->headers_out.content_length_n); return NGX_ERROR; } + len = (size_t) r->headers_out.content_length_n; + } else { len = clcf->subrequest_output_buffer_size; }