The length in the "VALUE" line was accepted up to NGX_MAX_OFF_T_VALUE,
while ngx_http_memcached_filter_init() adds the size of the end marker
to it. With lengths close to the maximum this overflowed u->length.
Now such lengths are rejected, similarly to other invalid lengths.
p = line.data + line.len;
u->headers_in.content_length_n = ngx_atoof(start, p - start);
- if (u->headers_in.content_length_n == NGX_ERROR) {
+
+ if (u->headers_in.content_length_n == NGX_ERROR
+ || u->headers_in.content_length_n
+ > NGX_MAX_OFF_T_VALUE - (off_t) NGX_HTTP_MEMCACHED_END)
+ {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"memcached sent invalid length in response \"%V\" "
"for key \"%V\"",