{"record":{"id":"c602e6cba71264bb","repo":"Anuken/Mindustry","slug":"invalid-array-size","errorCode":null,"errorMessage":"Invalid array size: {}","messagePattern":"Invalid array size: (.+?)","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"core/src/mindustry/io/TypeIO.java","lineNumber":203,"sourceCode":"        return switch(type){\n            case 0 -> null;\n            case 1 -> read.i();\n            case 2 -> read.l();\n            case 3 -> read.f();\n            case 4 -> {\n                byte exists = read.b();\n                if(exists != 0){\n                    //in a safe context, strings can only be 1200 chars\n                    yield read.str(safe ? 1200 : 0);\n                }else{\n                    yield null;\n                }\n            }\n            case 5 -> mapper == null ? content.getByID(ContentType.all[read.b()], read.s()) : mapper.get(ContentType.all[read.b()], read.s());\n            case 6 -> {\n                if(!allowArrays) throw new RuntimeException(\"Nested arrays are not allowed\");\n                short len = read.s();\n                if(len > maxArraySize) throw new RuntimeException(\"Invalid array size: \" + len);\n                IntSeq arr = new IntSeq(len);\n                for(int i = 0; i < len; i ++) arr.add(read.i());\n                yield arr;\n            }\n            case 7 -> new Point2(read.i(), read.i());\n            case 8 -> {\n                if(!allowArrays) throw new RuntimeException(\"Nested arrays are not allowed\");\n                int len = read.ub();\n                Point2[] out = new Point2[len];\n                for(int i = 0; i < len; i ++) out[i] = Point2.unpack(read.i());\n                yield out;\n            }\n            case 9 -> content.<UnlockableContent>getByID(ContentType.all[read.b()], read.s()).techNode;\n            case 10 -> read.bool();\n            case 11 -> read.d();\n            case 12 -> !box ? world.build(read.i()) : new BuildingBox(read.i());\n            case 13 -> LAccess.all[read.s()];\n            case 14 -> {","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/core/src/mindustry/io/TypeIO.java#L185-L221","documentation":"TypeIO.readObject case 6 (IntSeq) reads a short length and rejects it if it exceeds maxArraySize (1000, or 200 in unsafe contexts). This is a server-side sanity check against malicious or corrupt packets claiming an oversized IntSeq. Plain RuntimeException, not ArcRuntimeException.","triggerScenarios":"A client packet or save region where the IntSeq length short is greater than the effective maxArraySize; in safe contexts the limit is 1000, in non-safe (build-plan) contexts it is 200.","commonSituations":"A malicious/corrupt client sending an inflated length to force a large allocation; a version drift that misreads bytes as a length.","solutions":["Ensure the client respects the same maxArraySize caps when writing (writeObject already enforces 1000).","Treat this as a protocol violation: disconnect/log the offending client rather than retrying.","If developing a mod, never hand-craft TypeIO bytes; use writeObject/readObject pairs."],"exampleFix":"// before (client)\nwrite.s((short)5000); // bypasses writeObject; server read throws\n\n// after\nTypeIO.writeObject(write, intSeq); // writeObject enforces the 1000 cap\n// server: catch RuntimeException and kick the offending connection","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n    Object o = TypeIO.readObject(read);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Invalid array size\")) {\n        // protocol violation; disconnect offending client\n    }\n}","preventionTips":["Always write IntSeq via TypeIO.writeObject (enforces 1000 cap).","Treat oversized-length reads as malicious and drop the connection.","Never hand-craft TypeIO byte streams."],"tags":["network","deserialization","typeio","size-limit","security"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}