mirror of
https://github.com/fadden/6502bench.git
synced 2024-12-01 22:50:35 +00:00
Increase JSON size limit for project files
The JavaScriptSerializer class throws an exception if the JSON data exceeds a certain size. The default limit is 2MB, which is relatively easy to hit because of the verbosity of the serialized data. Super Mario Bros needs about 1MB of JSON for a binary with 32KB + gfx. Using that as a guide, we need 32x the source file size for a thoroughly-documented project. We currently limit the max binary size to 1MB for practical reasons, so a cap of 32MB should cover us. This change raises the limit to 64MB, with a slightly higher limit on the deserialization side because we add newlines for readability. This is more of a workaround than a fix, but it should do for now. (issue #137)
This commit is contained in:
parent
58d794f535
commit
7adec9f725
@ -54,6 +54,9 @@ namespace SourceGen {
|
||||
// may get lost as soon as they save the file.
|
||||
public const int CONTENT_VERSION = 5;
|
||||
|
||||
// Max JSON file length.
|
||||
internal const int MAX_JSON_LENGTH = 64 * 1024 * 1024;
|
||||
|
||||
private static readonly bool ADD_CRLF = true;
|
||||
|
||||
|
||||
@ -567,6 +570,7 @@ namespace SourceGen {
|
||||
}
|
||||
|
||||
JavaScriptSerializer ser = new JavaScriptSerializer();
|
||||
ser.MaxJsonLength = ProjectFile.MAX_JSON_LENGTH; // increase max len beyond 2MB
|
||||
string cereal = ser.Serialize(spf);
|
||||
sb.Append(cereal);
|
||||
|
||||
@ -586,6 +590,10 @@ namespace SourceGen {
|
||||
public static bool DeserializeProject(string cereal, DisasmProject proj,
|
||||
FileLoadReport report) {
|
||||
JavaScriptSerializer ser = new JavaScriptSerializer();
|
||||
// Increase max size of JSON data. We need to make the deserialization limit larger
|
||||
// than the serialization limit because we insert additional newlines to make the
|
||||
// file more readable. 1/64th of max is probably about right. TODO: fix this properly.
|
||||
ser.MaxJsonLength = ProjectFile.MAX_JSON_LENGTH + (ProjectFile.MAX_JSON_LENGTH / 64);
|
||||
SerializableProjectFile1 spf;
|
||||
try {
|
||||
spf = ser.Deserialize<SerializableProjectFile1>(cereal);
|
||||
|
Loading…
Reference in New Issue
Block a user