{"record":{"id":"d6962a51550cbcc7","repo":"EllanJiang/GameFramework","slug":"bytes-is-invalid-utility-verifier","errorCode":null,"errorMessage":"Bytes is invalid.","messagePattern":"Bytes is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Utility/Utility.Verifier.cs","lineNumber":33,"sourceCode":"        /// <summary>\n        /// 校验相关的实用函数。\n        /// </summary>\n        public static partial class Verifier\n        {\n            private const int CachedBytesLength = 0x1000;\n            private static readonly byte[] s_CachedBytes = new byte[CachedBytesLength];\n            private static readonly Crc32 s_Algorithm = new Crc32();\n\n            /// <summary>\n            /// 计算二进制流的 CRC32。\n            /// </summary>\n            /// <param name=\"bytes\">指定的二进制流。</param>\n            /// <returns>计算后的 CRC32。</returns>\n            public static int GetCrc32(byte[] bytes)\n            {\n                if (bytes == null)\n                {\n                    throw new GameFrameworkException(\"Bytes is invalid.\");\n                }\n\n                return GetCrc32(bytes, 0, bytes.Length);\n            }\n\n            /// <summary>\n            /// 计算二进制流的 CRC32。\n            /// </summary>\n            /// <param name=\"bytes\">指定的二进制流。</param>\n            /// <param name=\"offset\">二进制流的偏移。</param>\n            /// <param name=\"length\">二进制流的长度。</param>\n            /// <returns>计算后的 CRC32。</returns>\n            public static int GetCrc32(byte[] bytes, int offset, int length)\n            {\n                if (bytes == null)\n                {\n                    throw new GameFrameworkException(\"Bytes is invalid.\");\n                }","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Utility/Utility.Verifier.cs#L15-L51","documentation":"Utility.Verifier.GetCrc32(byte[]) computes a CRC32 over an entire byte array. It throws GameFrameworkException(\"Bytes is invalid.\") when the byte array argument is null, before delegating to the offset/length overload. This is a guard so callers get a clear framework exception instead of a NullReferenceException.","triggerScenarios":"Calling Utility.Verifier.GetCrc32(bytes) with a null byte[] — e.g. a file read that failed and returned null, or an uninitialized download buffer.","commonSituations":"Computing a checksum of a resource whose bytes failed to load; passing the result of a failed AssetBundle/WebRequest read; pipeline stage dropping a buffer on error without propagating it.","solutions":["Null-check the byte array before calling GetCrc32","Fix the upstream loader so it never yields a null buffer (throw or retry there instead)","Catch GameFrameworkException and treat it as a checksum-computation failure"],"exampleFix":"// before\nint crc = Utility.Verifier.GetCrc32(data); // data may be null\n// after\nint crc = data != null ? Utility.Verifier.GetCrc32(data) : 0;","handlingStrategy":"type-guard","validationCode":"if (bytes == null) { Log.Warning(\"Cannot CRC null buffer\"); return 0; }","typeGuard":"static bool IsValidBuffer(byte[] bytes) => bytes != null;","tryCatchPattern":"try { return Utility.Verifier.GetCrc32(bytes); }\ncatch (GameFrameworkException ex) { Log.Warning(\"CRC failed: {0}\", ex.Message); return 0; }","preventionTips":["Check loader results for null before checksum steps","Make load failures throw instead of returning null buffers","Guard checksum helpers behind non-null wrappers"],"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"}