{"record":{"id":"d1f008fe0c0a6fff","repo":"EllanJiang/GameFramework","slug":"code-is-invalid-utility-verifier","errorCode":null,"errorMessage":"Code is invalid.","messagePattern":"Code is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Utility/Utility.Verifier.cs","lineNumber":148,"sourceCode":"                    throw new GameFrameworkException(\"Offset or length is invalid.\");\n                }\n\n                bytes[offset] = (byte)((crc32 >> 24) & 0xff);\n                bytes[offset + 1] = (byte)((crc32 >> 16) & 0xff);\n                bytes[offset + 2] = (byte)((crc32 >> 8) & 0xff);\n                bytes[offset + 3] = (byte)(crc32 & 0xff);\n            }\n\n            internal static int GetCrc32(Stream stream, byte[] code, int length)\n            {\n                if (stream == null)\n                {\n                    throw new GameFrameworkException(\"Stream is invalid.\");\n                }\n\n                if (code == null)\n                {\n                    throw new GameFrameworkException(\"Code is invalid.\");\n                }\n\n                int codeLength = code.Length;\n                if (codeLength <= 0)\n                {\n                    throw new GameFrameworkException(\"Code length is invalid.\");\n                }\n\n                int bytesLength = (int)stream.Length;\n                if (length < 0 || length > bytesLength)\n                {\n                    length = bytesLength;\n                }\n\n                int codeIndex = 0;\n                while (true)\n                {\n                    int bytesRead = stream.Read(s_CachedBytes, 0, CachedBytesLength);","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Utility/Utility.Verifier.cs#L130-L166","documentation":"Utility.GetCrc32 throws GameFrameworkException with 'Code is invalid.' when the byte[] code parameter passed to it is null. The code array is the seed value used for the CRC32 computation, so a null array makes the calculation impossible and the library refuses to proceed. This is an argument-null guard, not a runtime failure.","triggerScenarios":"Calling Utility.Verifier.GetCrc32(stream, code, length) with code == null (any stream state).","commonSituations":"A field or variable holding the CRC seed was never initialized; deserialized config returned null; a caller misread the API and thought the code parameter was optional.","solutions":["Pass a non-null byte array as the code argument (typically a 4-byte seed).","Check for null before calling and supply a default seed such as new byte[] { 0, 0, 0, 0 }.","Fix upstream code that produced a null seed (failed deserialization, unset config)."],"exampleFix":"// before\nint crc = Utility.Verifier.GetCrc32(stream, code, length); // code is null\n// after\nbyte[] code = codeBytes ?? new byte[] { 0, 0, 0, 0 };\nint crc = Utility.Verifier.GetCrc32(stream, code, length);","handlingStrategy":"validation","validationCode":"if (stream != null && code != null && code.Length > 0)\n{\n    int crc = Utility.Verifier.GetCrc32(stream, code, length);\n}\nelse\n{\n    Log.Warning(\"GetCrc32 skipped: null stream or invalid code seed.\");\n}","typeGuard":"bool IsValidCrcSeed(byte[] code) => code != null && code.Length > 0;","tryCatchPattern":"try\n{\n    int crc = Utility.Verifier.GetCrc32(stream, code, length);\n}\ncatch (GameFrameworkException ex) when (ex.Message == \"Code is invalid.\" || ex.Message == \"Stream is invalid.\" || ex.Message == \"Code length is invalid.\")\n{\n    Log.Error(\"CRC32 computation failed: {0}\", ex.Message);\n}","preventionTips":["Initialize CRC seeds as constants (e.g. new byte[4]) rather than from possibly-null sources.","Add a debug.Assert on the seed before hashing code paths.","Wrap seed loading (file/config) so a load failure yields a default seed, never null."],"tags":["csharp","gameframework","null-argument","crc32","utility"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}