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:
1 parent
e0ffdddd47
commit
fd71a69fab
7 files changed
+1479
-21
No files matched your search
@@ -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