{"record":{"id":"d92ae58916f847cc","repo":"Anuken/Mindustry","slug":"objectives-bytes-too-long","errorCode":null,"errorMessage":"Objectives bytes too long: ","messagePattern":"Objectives bytes too long: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"core/src/mindustry/io/TypeIO.java","lineNumber":942,"sourceCode":"\n    public static Rules readRules(Reads read){\n        int length = read.i();\n        //this is only called clientside, but the byte limit is reasonable either way...\n        if(length > 100_000) throw new ArcRuntimeException(\"Rules too long\");\n        String string = new String(read.b(new byte[length]), charset);\n        return JsonIO.read(Rules.class, string);\n    }\n\n    public static void writeObjectives(Writes write, MapObjectives executor){\n        String string = JsonIO.write(executor);\n        byte[] bytes = string.getBytes(charset);\n        write.i(bytes.length);\n        write.b(bytes);\n    }\n\n    public static MapObjectives readObjectives(Reads read){\n        int length = read.i();\n        if(length >= 60_000) throw new RuntimeException(\"Objectives bytes too long: \" + length);\n        String string = new String(read.b(new byte[length]), charset);\n        return JsonIO.read(MapObjectives.class, string);\n    }\n\n    public static void writeObjectiveMarker(Writes write, ObjectiveMarker marker){\n        String string = JsonIO.json.toJson(marker, MapObjectives.ObjectiveMarker.class);\n        byte[] bytes = string.getBytes(charset);\n        write.i(bytes.length);\n        write.b(bytes);\n    }\n\n    public static ObjectiveMarker readObjectiveMarker(Reads read){\n        int length = read.i();\n        if(length > maxByteArraySize) throw new ArcRuntimeException(\"Objective marker too long\");\n        String string = new String(read.b(new byte[length]), charset);\n        return JsonIO.read(MapObjectives.ObjectiveMarker.class, string);\n    }\n","sourceCodeStart":924,"sourceCodeEnd":960,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/core/src/mindustry/io/TypeIO.java#L924-L960","documentation":"readObjectives() reads JSON-serialized MapObjectives. It reads a 4-byte length and throws RuntimeException if length >= 60_000 bytes. It bounds map-objective payloads (sent with map state) against memory abuse.","triggerScenarios":"A map-objectives packet whose int length field is >= 60_000.","commonSituations":"A map with very many objectives; a custom campaign map; corruption; a malicious source.","solutions":["Reduce the number and complexity of map objectives so JSON stays under 60KB.","Split large objective state across multiple markers or out-of-band."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before writing objectives, check serialized size against the read cap.\nString json = JsonIO.write(executor);\nif(json.getBytes(java.nio.charset.StandardCharsets.UTF_8).length >= 60_000){\n    throw new IllegalStateException(\"Objectives JSON too large\");\n}","typeGuard":null,"tryCatchPattern":"try { MapObjectives o = TypeIO.readObjectives(read); }\ncatch(RuntimeException e){ Log.err(\"Objectives payload too large\", e); /* handle */ }","preventionTips":["Keep map-objective JSON under 60KB.","Avoid huge objective graphs in custom maps."],"tags":["network","objectives","deserialization","security"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}