Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Fix crash when style JSON does not have an object at its root #5736

Merged
merged 2 commits into from
Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion src/mbgl/style/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ 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();
const JSValue& versionValue = document["version"];
const int version = versionValue.IsNumber() ? versionValue.GetInt() : 0;
if (version != 8) {
Log::Warning(Event::ParseStyle, "current renderer implementation only supports style spec version 8; using an outdated style will cause rendering errors");
}
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/style_parser/non-object.info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"default": {
"log": [
[1, "ERROR", "ParseStyle", "Style JSON must be an object"]
]
}
}
1 change: 1 addition & 0 deletions test/fixtures/style_parser/non-object.style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""
7 changes: 7 additions & 0 deletions test/fixtures/style_parser/version-not-number.info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"default": {
"log": [
[1, "WARNING", "ParseStyle", "current renderer implementation only supports style spec version 8; using an outdated style will cause rendering errors"]
]
}
}
1 change: 1 addition & 0 deletions test/fixtures/style_parser/version-not-number.style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"8"}