{"record":{"id":"3243e7bd05848c17","repo":"dotnet/wpf","slug":"input-or-compressed-data-was-null-in-compress","errorCode":null,"errorMessage":"input or compressed data was null in Compress","messagePattern":"input or compressed data was null in Compress","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/GorillaCodec.cs","lineNumber":362,"sourceCode":"            {\n                bitCount = (int)_gorIndexMap[index].BitCount;\n                padCount = (int)_gorIndexMap[index].PadCount;\n            }\n        }\n\n        /// <summary>\n        /// Compress - compress the input[] into compressedData\n        /// </summary>\n        /// <param name=\"bitCount\">The count of bits needed for all elements</param>\n        /// <param name=\"input\">input buffer</param>\n        /// <param name=\"startInputIndex\">offset into the input buffer</param>\n        /// <param name=\"dtxf\">data transform.  can be null</param>\n        /// <param name=\"compressedData\">The list of bytes to write the compressed input to</param>\n        internal void Compress(int bitCount, int[] input, int startInputIndex, DeltaDelta dtxf, List<byte> compressedData)\n        {\n            if (null == input || null == compressedData)\n            {\n                throw new ArgumentNullException(StrokeCollectionSerializer.ISFDebugMessage(\"input or compressed data was null in Compress\"));\n            }\n            ArgumentOutOfRangeException.ThrowIfNegative(bitCount);\n\n            if (bitCount == 0)\n            {\n                //adjust if the bitcount is 0\n                //(this makes bitCount 32)\n                bitCount = (int)(Native.SizeOfInt << 3);\n            }\n\n            //have the writer adapt to the List<byte> passed in and write to it\n            BitStreamWriter writer = new BitStreamWriter(compressedData);\n            if (null != dtxf)\n            {\n                int xfData = 0;\n                int xfExtra = 0;\n                for (int i = startInputIndex; i < input.Length; i++)\n                {","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/GorillaCodec.cs#L344-L380","documentation":"GorillaCodec.Compress validates its inputs: the int[] payload (input) and the List<byte> output (compressedData) must both be non-null, otherwise ArgumentNullException is thrown with this message. Gorilla compression is used internally when serializing stroke packet data to ISF; passing null buffers is a programming error by the caller.","triggerScenarios":"Calling Compress(bitCount, input, startInputIndex, dtxf, compressedData) with input == null or compressedData == null — typically in custom code that drives the Gorilla codec directly or a bug in a custom data pipeline that forgot to allocate the output list.","commonSituations":"Custom ink serialization code reusing GorillaCodec; refactoring that left a list uninitialized before compression; unit tests exercising the codec with placeholder nulls.","solutions":["Allocate the output buffer before compressing: compressedData = new List<byte>();","Ensure input packet array is created and populated (even empty) rather than null.","Add null checks/guards in the calling code before invoking Compress.","Prefer the public StrokeCollection.Save API which initializes all buffers for you."],"exampleFix":"// before\nList<byte> compressedData = null;\ncodec.Compress(8, packetData, 0, dtxf, compressedData);\n// after\nList<byte> compressedData = new List<byte>(packetData.Length);\ncodec.Compress(8, packetData, 0, dtxf, compressedData);","handlingStrategy":"validation","validationCode":"if (input == null) throw new ArgumentNullException(nameof(input));\nif (compressedData == null) throw new ArgumentNullException(nameof(compressedData));","typeGuard":"bool CanCompress(int[] input, List<byte> outBuf) => input != null && outBuf != null;","tryCatchPattern":"try { codec.Compress(bitCount, packets, 0, dtxf, outBuf); }\ncatch (ArgumentNullException ex) { log.Error(\"Gorilla compress buffers missing\", ex); throw; }","preventionTips":["Always allocate the output List<byte> before compressing.","Treat empty arrays as valid; never pass null as a placeholder.","Initialize codec inputs in one place to avoid scattered nulls."],"tags":["ink","gorilla-codec","compression","null-argument"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}