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

Fixture tester should not access invalid array entries #87

Open
springmeyer opened this issue Apr 22, 2018 · 0 comments
Open

Fixture tester should not access invalid array entries #87

springmeyer opened this issue Apr 22, 2018 · 0 comments
Assignees

Comments

@springmeyer
Copy link
Contributor

The fixture tester is not careful to check that the coordinate arrays it is parsing in this loop:

for (SizeType j = 0; j < document[i].Size(); ++j) {
lr.push_back({ document[i][j][0].GetInt(), document[i][j][1].GetInt() });
}
have both X and Y values. This means that an invalid JSON file like:

[
    [
   [-2500],
     [-2500.20], [-25250000,-2,-2500],
   [-2500.2500],
   [250062500],
   [2500,-2560],[-2500,-2500] ]
]

Will result in bogus values in release mode like:

-2500 0
1717986918 0
-25250000 -2
0 250062500
250062500 2500
2500 -2560
-2500 -2500

^^ generated by doing:

diff --git a/tests/fixture-tester.cpp b/tests/fixture-tester.cpp
index 02036d7..b1dde95 100644
--- a/tests/fixture-tester.cpp
+++ b/tests/fixture-tester.cpp
@@ -103,6 +103,7 @@ mapbox::geometry::polygon<value_type> parse_file(const char* file_path) {
                                      ") is not a valid json array");
         }
         for (SizeType j = 0; j < document[i].Size(); ++j) {
+            std::clog << document[i][j][0].GetInt() << " " << document[i][j][1].GetInt() << "\n";
             lr.push_back({ document[i][j][0].GetInt(), document[i][j][1].GetInt() });
         }
         poly.emplace_back(lr);

And in debug mode rapidjson catches the problem:

Assertion failed: (index < data_.a.size), function operator[], file mason_packages/headers/rapidjson/1.1.0/include/rapidjson/document.h, line 1498.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants