{"record":{"id":"091a11724fc7d460","repo":"EllanJiang/GameFramework","slug":"stream-is-invalid-utility-verifier","errorCode":null,"errorMessage":"Stream is invalid.","messagePattern":"Stream is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Utility/Utility.Verifier.cs","lineNumber":73,"sourceCode":"                    throw new GameFrameworkException(\"Offset or length is invalid.\");\n                }\n\n                s_Algorithm.HashCore(bytes, offset, length);\n                int result = (int)s_Algorithm.HashFinal();\n                s_Algorithm.Initialize();\n                return result;\n            }\n\n            /// <summary>\n            /// 计算二进制流的 CRC32。\n            /// </summary>\n            /// <param name=\"stream\">指定的二进制流。</param>\n            /// <returns>计算后的 CRC32。</returns>\n            public static int GetCrc32(Stream stream)\n            {\n                if (stream == null)\n                {\n                    throw new GameFrameworkException(\"Stream is invalid.\");\n                }\n\n                while (true)\n                {\n                    int bytesRead = stream.Read(s_CachedBytes, 0, CachedBytesLength);\n                    if (bytesRead > 0)\n                    {\n                        s_Algorithm.HashCore(s_CachedBytes, 0, bytesRead);\n                    }\n                    else\n                    {\n                        break;\n                    }\n                }\n\n                int result = (int)s_Algorithm.HashFinal();\n                s_Algorithm.Initialize();\n                Array.Clear(s_CachedBytes, 0, CachedBytesLength);","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Utility/Utility.Verifier.cs#L55-L91","documentation":"The stream-based Utility.Verifier.GetCrc32(Stream) computes a CRC32 by streaming through the stream in chunks. It throws GameFrameworkException(\"Stream is invalid.\") when the stream argument is null. The guard ensures the library never dereferences a null stream.","triggerScenarios":"Calling Utility.Verifier.GetCrc32(stream) with a null Stream — e.g. File.OpenRead failed upstream and null was propagated, or a resource loader returned null on failure.","commonSituations":"Verifying a downloaded package file before the stream was opened; a Unity WWW/WebRequest path where the response stream is null on error; passing a disposed-or-never-created stream stored in a field.","solutions":["Ensure the stream is opened successfully before calling GetCrc32; null-check the result of File.Open/asset load","Fix the loader so it throws on failure rather than returning null","Catch GameFrameworkException and surface a friendly 'file could not be verified' error"],"exampleFix":"// before\nStream s = OpenFile(path); // may return null\nint crc = Utility.Verifier.GetCrc32(s);\n// after\nusing (Stream s = File.OpenRead(path))\n{\n    int crc = Utility.Verifier.GetCrc32(s);\n}","handlingStrategy":"type-guard","validationCode":"if (stream == null) throw new FileNotFoundException(\"stream not opened\");","typeGuard":"static bool IsOpen(Stream stream) => stream != null && stream.CanRead;","tryCatchPattern":"try { return Utility.Verifier.GetCrc32(stream); }\ncatch (GameFrameworkException ex) { Log.Warning(\"Stream CRC failed: {0}\", ex.Message); return 0; }","preventionTips":["Open files with using/File.OpenRead so failure throws instead of yielding null","Check CanRead before hashing","Verify downloads complete before checksum verification"],"tags":["null-argument","stream","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"}