diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-07-20 13:16:49 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-07-20 15:33:09 +0200 |
commit | a07fbe8e34a31fd28266cede03162258efe642c3 (patch) | |
tree | 941d1a24bb0e8c83ffb0f4d7d36e2cbef3d0acae | |
parent | 000539af828b0b3b0a7b0f145434b2556b5a08c3 (diff) | |
download | qtlocation-mapboxgl-a07fbe8e34a31fd28266cede03162258efe642c3.tar.gz |
[core] fix crash when the style JSON doesn't have an object at its root
-rw-r--r-- | src/mbgl/style/parser.cpp | 5 | ||||
-rw-r--r-- | test/fixtures/style_parser/non-object.info.json | 7 | ||||
-rw-r--r-- | test/fixtures/style_parser/non-object.style.json | 1 |
3 files changed, 13 insertions, 0 deletions
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp index 41b23c1bae..56e6f8ad01 100644 --- a/src/mbgl/style/parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -29,6 +29,11 @@ void Parser::parse(const std::string& json) { return; } + if (!document.IsObject()) { + Log::Error(Event::ParseStyle, "Style JSON must be an object"); + return; + } + if (document.HasMember("version")) { int version = document["version"].GetInt(); if (version != 8) { diff --git a/test/fixtures/style_parser/non-object.info.json b/test/fixtures/style_parser/non-object.info.json new file mode 100644 index 0000000000..d1b67e2ea6 --- /dev/null +++ b/test/fixtures/style_parser/non-object.info.json @@ -0,0 +1,7 @@ +{ + "default": { + "log": [ + [1, "ERROR", "ParseStyle", "Style JSON must be an object"] + ] + } +}
\ No newline at end of file diff --git a/test/fixtures/style_parser/non-object.style.json b/test/fixtures/style_parser/non-object.style.json new file mode 100644 index 0000000000..3cc762b550 --- /dev/null +++ b/test/fixtures/style_parser/non-object.style.json @@ -0,0 +1 @@ +""
\ No newline at end of file |