Skip to content

Commit

Permalink
17499: Fixes crash when attempting to parse invalid json (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
howsohazard authored Sep 14, 2023
1 parent e6277a8 commit d855d14
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/Amalgam/importexport/FileSupportJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,36 +279,36 @@ EvaluableNode *EvaluableNodeJSONTranslation::JsonToEvaluableNode(EvaluableNodeMa
auto json_padded = simdjson::padded_string(json_str);
auto json_top_element = json_parser.iterate(json_padded);

//simdjson needs special handling if the top element is a scalar
if(json_top_element.is_scalar())
try
{
switch(json_top_element.type())
//simdjson needs special handling if the top element is a scalar
if(json_top_element.is_scalar())
{
case simdjson::ondemand::json_type::number:
return enm->AllocNode(json_top_element.get_double());
switch(json_top_element.type())
{
case simdjson::ondemand::json_type::number:
return enm->AllocNode(json_top_element.get_double());

case simdjson::ondemand::json_type::string:
{
std::string_view str_view = json_top_element.get_string();
std::string str(str_view);
return enm->AllocNode(ENT_STRING, str);
}
case simdjson::ondemand::json_type::string:
{
std::string_view str_view = json_top_element.get_string();
std::string str(str_view);
return enm->AllocNode(ENT_STRING, str);
}

case simdjson::ondemand::json_type::boolean:
{
if(json_top_element.get_bool())
return enm->AllocNode(ENT_TRUE);
else
return enm->AllocNode(ENT_FALSE);
}
case simdjson::ondemand::json_type::boolean:
{
if(json_top_element.get_bool())
return enm->AllocNode(ENT_TRUE);
else
return enm->AllocNode(ENT_FALSE);
}

default:
return nullptr;
default:
return nullptr;
}
}
}

try
{
return JsonToEvaluableNodeRecurse(enm, json_top_element);
}
catch(simdjson::simdjson_error &e)
Expand Down

0 comments on commit d855d14

Please sign in to comment.