From: Philippe Antoine Date: Wed, 31 May 2023 12:53:28 +0000 (+0200) Subject: http2: avoid quadratic complexity in headers X-Git-Tag: suricata-7.0.0-rc2~83 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=635073688289aa9a4928f78cdfd1777ae21f7d40;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 --- diff --git a/rust/src/http2/parser.rs b/rust/src/http2/parser.rs index 88486f03b0..adabeb28c6 100644 --- a/rust/src/http2/parser.rs +++ b/rust/src/http2/parser.rs @@ -456,13 +456,15 @@ fn http2_parse_headers_block_literal_incindex<'a>( } else { dyn_headers.table.push(headcopy); } + let mut toremove = 0; while dyn_headers.current_size > dyn_headers.max_size - && !dyn_headers.table.is_empty() + && 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)); }