diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp index 41b23c1ba..56e6f8ad0 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 000000000..d1b67e2ea --- /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 000000000..3cc762b55 --- /dev/null +++ b/test/fixtures/style_parser/non-object.style.json @@ -0,0 +1 @@ +"" \ No newline at end of file