Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(src): avoid possible infinite loop in LoadAll(). #1319

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ std::vector<Node> LoadAll(std::istream& input) {
Parser parser(input);
while (true) {
NodeBuilder builder;
if (!parser.HandleNextDocument(builder)) {
if (!parser.HandleNextDocument(builder) || builder.Root().IsNull()) {
break;
}
docs.push_back(builder.Root());
Expand Down
7 changes: 7 additions & 0 deletions test/integration/node_spec_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,13 @@ TEST(NodeSpecTest, Ex7_24_FlowNodes) {
EXPECT_EQ("", doc[4].as<std::string>());
}

TEST(NodeSpecTest, Ex7_25_InfiniteLoopNodes) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file is just for the spec tests, ie, examples literally in the spec.

Can you add it to node_test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)
Thanks for the feedback! (and agree about github's UI :/ )

Copy link
Contributor Author

@FedeDP FedeDP Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see 2 CI failures that don't seem to be caused by my commits:

/usr/include/gtest/internal/gtest-port.h:279:2: error: #error C++ versions less than C++14 are not supported.
279 | #error C++ versions less than C++14 are not supported.

I think they bumped gtest version and it now requires c++14, therefore all jobs that use deps from system and building against c++11 will fail.

// Until yaml-cpp <= 0.8.0 this caused an infinite loop;
// After, it triggers an exception (but LoadAll is smart enough to avoid
// the infinite loop in any case).
ASSERT_THROW(LoadAll(ex7_25), ParserException);
}

TEST(NodeSpecTest, Ex8_1_BlockScalarHeader) {
Node doc = Load(ex8_1);
EXPECT_EQ(4, doc.size());
Expand Down
3 changes: 3 additions & 0 deletions test/specexamples.h
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,9 @@ const char *ex7_24 =
"- *anchor\n"
"- !!str";

const char *ex7_25 =
",";

const char *ex8_1 =
"- | # Empty header\n"
" literal\n"
Expand Down