From: Philippe Antoine Date: Wed, 31 May 2023 12:53:28 +0000 (+0200) Subject: http2: avoid quadratic complexity in headers X-Git-Tag: suricata-6.0.13~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=401a1b36b1754dfb67d65def53c6304ae89d39e9;p=thirdparty%2Fsuricata.git http2: avoid quadratic complexity in headers When adding an element to the dynamic headers table, the oldest ones may get evicted. When multiple elements get evicted, they should get evicted all at once with drain, instead of one by one as there will be a massive move each time. Ticket: #6103 (cherry picked from commit 635073688289aa9a4928f78cdfd1777ae21f7d40) --- diff --git a/rust/src/http2/parser.rs b/rust/src/http2/parser.rs index d99efd95a6..2d4f363bfa 100644 --- a/rust/src/http2/parser.rs +++ b/rust/src/http2/parser.rs @@ -457,12 +457,15 @@ fn http2_parse_headers_block_literal_incindex<'a>( } else { dyn_headers.table.push(headcopy); } - while dyn_headers.current_size > dyn_headers.max_size && dyn_headers.table.len() > 0 + let mut toremove = 0; + while dyn_headers.current_size > dyn_headers.max_size + && toremove < dyn_headers.table.len() { dyn_headers.current_size -= - 32 + dyn_headers.table[0].name.len() + dyn_headers.table[0].value.len(); - dyn_headers.table.remove(0); + 32 + dyn_headers.table[toremove].name.len() + dyn_headers.table[toremove].value.len(); + toremove += 1; } + dyn_headers.table.drain(0..toremove); } return Ok((r, head)); }