{"record":{"id":"8bcc52c883328e05","repo":"EllanJiang/GameFramework","slug":"compressed-stream-is-invalid","errorCode":null,"errorMessage":"Compressed stream is invalid.","messagePattern":"Compressed stream is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Utility/Utility.Compression.cs","lineNumber":111,"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 (compressedStream == null)\n                {\n                    throw new GameFrameworkException(\"Compressed stream is invalid.\");\n                }\n\n                try\n                {\n                    return s_CompressionHelper.Compress(bytes, offset, length, compressedStream);\n                }\n                catch (Exception exception)\n                {\n                    if (exception is GameFrameworkException)\n                    {\n                        throw;\n                    }\n\n                    throw new GameFrameworkException(Text.Format(\"Can not compress with exception '{0}'.\", exception), exception);\n                }\n            }\n\n            /// <summary>","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Utility/Utility.Compression.cs#L93-L129","documentation":"Guard in CompressionHelper.Compress: thrown when the compressedStream argument is null. After validating the helper and the input bytes/offset/length, compression needs a destination stream to write into; a null stream means there is nowhere to put the compressed output, so the call fails fast.","triggerScenarios":"Calling Compress(bytes, offset, length, null); passing a stream variable that failed to open or was disposed/nulled earlier.","commonSituations":"File.Open failing upstream and the stream variable staying null; disposing a stream before compression; forgetting to create a MemoryStream wrapper.","solutions":["Create/open the destination stream before compressing (e.g. new MemoryStream())","Check that any stream-opening code succeeded and was not disposed early","Validate stream != null at the call site"],"exampleFix":"// before\nStream stream = OpenOutputFile(); // may return null\nUtility.Compression.Compress(data, 0, data.Length, stream);\n// after\nusing (Stream stream = File.Create(path))\n{\n    Utility.Compression.Compress(data, 0, data.Length, stream);\n}","handlingStrategy":"validation","validationCode":"if (compressedStream == null) throw new ArgumentNullException(nameof(compressedStream));","typeGuard":"bool HasDestination(Stream compressedStream) => compressedStream != null && compressedStream.CanWrite;","tryCatchPattern":"try { Utility.Compression.Compress(bytes, 0, bytes.Length, stream); } catch (GameFrameworkException ex) { Log.Error(\"Compression stream invalid: \" + ex.Message); }","preventionTips":["Open destination streams with using statements before compression","Check file-open results instead of passing possibly-null streams","Never dispose a stream before the compress call completes"],"tags":["compression","null-argument","stream"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}