{"record":{"id":"b19d0549c2247800","repo":"EllanJiang/GameFramework","slug":"result-is-invalid-utility-verifier","errorCode":null,"errorMessage":"Result is invalid.","messagePattern":"Result is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Utility/Utility.Verifier.cs","lineNumber":125,"sourceCode":"            /// </summary>\n            /// <param name=\"crc32\">CRC32 数值。</param>\n            /// <param name=\"bytes\">要存放结果的数组。</param>\n            public static void GetCrc32Bytes(int crc32, byte[] bytes)\n            {\n                GetCrc32Bytes(crc32, bytes, 0);\n            }\n\n            /// <summary>\n            /// 获取 CRC32 数值的二进制数组。\n            /// </summary>\n            /// <param name=\"crc32\">CRC32 数值。</param>\n            /// <param name=\"bytes\">要存放结果的数组。</param>\n            /// <param name=\"offset\">CRC32 数值的二进制数组在结果数组内的起始位置。</param>\n            public static void GetCrc32Bytes(int crc32, byte[] bytes, int offset)\n            {\n                if (bytes == null)\n                {\n                    throw new GameFrameworkException(\"Result is invalid.\");\n                }\n\n                if (offset < 0 || offset + 4 > bytes.Length)\n                {\n                    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.\");","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Utility/Utility.Verifier.cs#L107-L143","documentation":"Utility.Verifier.GetCrc32Bytes(int crc32, byte[] bytes, int offset) writes the 4-byte big-endian representation of a CRC32 into a caller-supplied array. It throws GameFrameworkException(\"Result is invalid.\") when the target byte array is null, guarding before the writes occur.","triggerScenarios":"Calling GetCrc32Bytes(crc32, result, offset) with result == null — e.g. the output buffer was never allocated or an earlier allocation failed and null propagated.","commonSituations":"Preparing version/checksum bytes for a package manifest where the result buffer comes from a pooled allocator that returned null; refactored code that dropped the buffer allocation.","solutions":["Allocate the result array (at least offset + 4 bytes) before calling","Null-check the result buffer at the call site","Catch GameFrameworkException to report buffer-preparation failures"],"exampleFix":"// before\nUtility.Verifier.GetCrc32Bytes(crc, result, 0); // result null\n// after\nbyte[] result = new byte[4];\nUtility.Verifier.GetCrc32Bytes(crc, result, 0);","handlingStrategy":"validation","validationCode":"if (result == null || result.Length < offset + 4) throw new InvalidOperationException(\"result buffer too small\");","typeGuard":"static bool CanHoldCrc(byte[] bytes, int offset) => bytes != null && offset >= 0 && offset + 4 <= bytes.Length;","tryCatchPattern":"try { Utility.Verifier.GetCrc32Bytes(crc, result, 0); }\ncatch (GameFrameworkException ex) { Log.Warning(\"CRC write failed: {0}\", ex.Message); }","preventionTips":["Always allocate output buffers explicitly before CRC writes","Keep pooled-buffer allocations null-checked","Prefer new byte[4] over nullable buffer fields for checksum output"],"tags":["null-argument","checksum","crc32","gameframework"],"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"}