mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Rewrite message parsing using string_view
It's a bit too early yet to require C++17 so the implementation from BackportCpp (string_view-standalone) is used instead. Fixes https://crbug.com/oss-fuzz/34413 - slow message parsing on huge messages. In real word, messages can't be that big, because CSocket enforces a line length limit. This can be considered a regression of 1.7.0, because before it, instead of gathering params into a vector, code was searching 1st word in the string, then 2nd word, then 3rd word, starting from beginning each time. It was not very efficient, but the number of passes over the string was limited.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
using ::testing::IsEmpty;
|
||||
using ::testing::ContainerEq;
|
||||
using ::testing::ElementsAre;
|
||||
using ::testing::SizeIs;
|
||||
|
||||
TEST(MessageTest, SetParam) {
|
||||
CMessage msg;
|
||||
@@ -609,3 +610,12 @@ TEST(MessageTest, ParseWithoutSourceAndTags) {
|
||||
EXPECT_EQ(msg.GetCommand(), "COMMAND");
|
||||
EXPECT_EQ(msg.GetParams(), VCString());
|
||||
}
|
||||
|
||||
TEST(MessageTest, HugeParse) {
|
||||
CString line;
|
||||
for (int i = 0; i < 1000000; ++i) {
|
||||
line += "a ";
|
||||
}
|
||||
CMessage msg(line);
|
||||
EXPECT_THAT(msg.GetParams(), SizeIs(999999));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user