{"record":{"id":"dc725510ab7724be","repo":"EllanJiang/GameFramework","slug":"decompressed-stream-is-invalid","errorCode":null,"errorMessage":"Decompressed stream is invalid.","messagePattern":"Decompressed stream is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Utility/Utility.Compression.cs","lineNumber":267,"sourceCode":"            {\n                if (s_CompressionHelper == null)\n                {\n                    throw new GameFrameworkException(\"Compressed helper is invalid.\");\n                }\n\n                if (bytes == null)\n                {\n                    throw new GameFrameworkException(\"Bytes is invalid.\");\n                }\n\n                if (offset < 0 || length < 0 || offset + length > bytes.Length)\n                {\n                    throw new GameFrameworkException(\"Offset or length is invalid.\");\n                }\n\n                if (decompressedStream == null)\n                {\n                    throw new GameFrameworkException(\"Decompressed stream is invalid.\");\n                }\n\n                try\n                {\n                    return s_CompressionHelper.Decompress(bytes, offset, length, decompressedStream);\n                }\n                catch (Exception exception)\n                {\n                    if (exception is GameFrameworkException)\n                    {\n                        throw;\n                    }\n\n                    throw new GameFrameworkException(Text.Format(\"Can not decompress with exception '{0}'.\", exception), exception);\n                }\n            }\n\n            /// <summary>","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Utility/Utility.Compression.cs#L249-L285","documentation":"Utility.Decompress validates its arguments before attempting decompression. This GameFrameworkException is thrown when the caller passes a null decompressedStream to Decompress(byte[] bytes, int offset, int length, Stream decompressedStream). The framework requires a valid destination stream to write the decompressed data into.","triggerScenarios":"Calling Utility.Decompress(bytes, offset, length, null) — i.e. passing null as the decompressedStream parameter.","commonSituations":"Developers caching a stream in a field that was never initialized, refactoring code so the stream is disposed/set to null before the decompress call, or forgetting to create the MemoryStream intended to receive the output.","solutions":["Create a valid destination stream (e.g. new MemoryStream()) and pass it to Decompress.","Add a null check on the stream before calling Decompress to fail fast with a clearer message.","If the stream comes from another method, verify that method cannot return null."],"exampleFix":"// before\nStream output = GetOutput(); // may return null\nUtility.Decompress(data, 0, data.Length, output);\n\n// after\nusing (var output = new MemoryStream())\n{\n    Utility.Decompress(data, 0, data.Length, output);\n    ...\n}","handlingStrategy":"validation","validationCode":"if (output == null) throw new ArgumentException(\"decompressedStream must be created before Decompress\");","typeGuard":"bool IsValidStream(Stream s) => s != null;","tryCatchPattern":"try { Utility.Decompress(bytes, offset, length, output); } catch (GameFrameworkException ex) { /* output stream was null or invalid */ }","preventionTips":["Always create the destination stream (new MemoryStream()) immediately before the call","Use 'using' blocks so stream lifetime is scoped to the decompress operation","Never assign null to stream fields after disposal"],"tags":["null-argument","compression","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-15T23:17:13.987Z"}