Handle parsing malformed user created VRC config.json files

This commit is contained in:
Natsumi
2025-05-28 23:58:08 +10:00
parent 9f45d535a0
commit 834e5fc245
5 changed files with 36 additions and 5 deletions

View File

@@ -28,7 +28,7 @@ namespace VRCX
if (string.IsNullOrEmpty(json))
return defaultPath;
var obj = JsonConvert.DeserializeObject<JObject>(json);
var obj = JsonConvert.DeserializeObject<JObject>(json, JsonSerializerSettings);
if (obj["cache_directory"] == null)
return defaultPath;
@@ -58,7 +58,7 @@ namespace VRCX
if (string.IsNullOrEmpty(json))
return defaultPath;
var obj = JsonConvert.DeserializeObject<JObject>(json);
var obj = JsonConvert.DeserializeObject<JObject>(json, JsonSerializerSettings);
if (obj["picture_output_folder"] == null)
return defaultPath;

View File

@@ -6,6 +6,7 @@ using System.IO;
using System.Security.Cryptography;
using System.Text;
using librsync.net;
using Newtonsoft.Json;
using NLog;
namespace VRCX
@@ -18,6 +19,14 @@ namespace VRCX
public void Init()
{
}
public JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
{
Error = delegate(object _, Newtonsoft.Json.Serialization.ErrorEventArgs args)
{
args.ErrorContext.Handled = true;
}
};
public string MD5File(string blob)
{

View File

@@ -1,5 +1,6 @@
using System;
using System.IO;
using Newtonsoft.Json;
namespace VRCX
{
@@ -18,6 +19,27 @@ namespace VRCX
return json;
}
public string ReadConfigFileSafe()
{
try
{
var configFile = ReadConfigFile();
if (string.IsNullOrEmpty(configFile))
return string.Empty;
var jObject = JsonConvert.DeserializeObject<dynamic>(configFile, JsonSerializerSettings);
if (jObject == null)
return string.Empty;
return JsonConvert.SerializeObject(jObject, Formatting.Indented);
}
catch (Exception ex)
{
logger.Warn(ex, "Failed to parse VRC config.json file");
return string.Empty;
}
}
public void WriteConfigFile(string json)
{
var path = GetVRChatAppDataLocation();

View File

@@ -93,7 +93,7 @@ namespace VRCX
if (string.IsNullOrEmpty(json))
return defaultPath;
var obj = JsonConvert.DeserializeObject<JObject>(json);
var obj = JsonConvert.DeserializeObject<JObject>(json, JsonSerializerSettings);
if (obj["cache_directory"] == null)
return defaultPath;
@@ -123,7 +123,7 @@ namespace VRCX
if (string.IsNullOrEmpty(json))
return defaultPath;
var obj = JsonConvert.DeserializeObject<JObject>(json);
var obj = JsonConvert.DeserializeObject<JObject>(json, JsonSerializerSettings);
if (obj["picture_output_folder"] == null)
return defaultPath;

View File

@@ -401,7 +401,7 @@
}
async function readVRChatConfigFile() {
const config = await AppApi.ReadConfigFile();
const config = await AppApi.ReadConfigFileSafe();
if (config) {
try {
const parsedConfig = JSON.parse(config);