json serialize seems to allow corrupted urf8 string, add a check when reading back to avoid crashing, ref #607

This commit is contained in:
emeric
2025-02-07 17:01:59 +01:00
parent d625f749b6
commit df93425748
+6
View File
@@ -81,6 +81,8 @@ namespace lms::db
std::vector<std::filesystem::path> PlayListFile::getFiles() const std::vector<std::filesystem::path> PlayListFile::getFiles() const
{ {
std::vector<std::filesystem::path> files; std::vector<std::filesystem::path> files;
try
{ {
Wt::Json::Object root; Wt::Json::Object root;
Wt::Json::parse(_entries, root); Wt::Json::parse(_entries, root);
@@ -90,6 +92,10 @@ namespace lms::db
for (const Wt::Json::Value& file : filesArray) for (const Wt::Json::Value& file : filesArray)
files.push_back(static_cast<std::string>(file.toString())); files.push_back(static_cast<std::string>(file.toString()));
} }
catch (const Wt::Json::ParseError& e)
{
LMS_LOG(DB, ERROR, "Cannot parse files saved in " << _absoluteFilePath << ": corrupted data?");
}
return files; return files;
} }