{"record":{"id":"e2a9a11c20f969ff","repo":"dotnet/wpf","slug":"bogus-gorillaencodingtype-passed-to-uncompress","errorCode":null,"errorMessage":"bogus GorillaEncodingType passed to Uncompress","messagePattern":"bogus GorillaEncodingType passed to Uncompress","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/GorillaCodec.cs","lineNumber":623,"sourceCode":"                        bitsToWrite = Native.BitsPerShort;\n                        //shorts are decoded as unsigned values, no mask required\n                        bitMask = 0;\n                        break;\n                    }\n                case GorillaEncodingType.Byte:\n                    {\n                        if (bitCount == 0)\n                        {\n                            bitCount = Native.BitsPerByte;\n                        }\n                        bitsToWrite = Native.BitsPerByte;\n                        //bytes are decoded as unsigned values, no mask required\n                        bitMask = 0;\n                        break;\n                    }\n                default:\n                    {\n                        throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage(\"bogus GorillaEncodingType passed to Uncompress\"));\n                    }\n            }\n            List<byte> output = new List<byte>((bitsToWrite / 8) * unitsToDecode);\n            BitStreamWriter writer = new BitStreamWriter(output);\n            uint bitData = 0;\n\n            while (!reader.EndOfStream && unitsToDecode > 0)\n            {\n                //we're going to cast to an uint anyway, just read as one\n                bitData = reader.ReadUInt32(bitCount);\n                // Construct the item\n                bitData = ((bitData & bitMask) != 0) ? bitMask | bitData : bitData;\n                writer.WriteReverse(bitData, bitsToWrite);\n                unitsToDecode--;\n            }\n\n            return output.ToArray();\n        }","sourceCodeStart":605,"sourceCodeEnd":641,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/GorillaCodec.cs#L605-L641","documentation":"GorillaCodec.Uncompress switches on the GorillaEncodingType to set the bit mask and decode strategy; an unrecognized type reaches the default case and throws ArgumentException with this message. Like its Compress/GetDataFromReader counterparts, it defends the decompression path against encodings it does not implement.","triggerScenarios":"Calling Uncompress with an invalid GorillaEncodingType — usually a value read from ISF-encoded stroke data that is Unknown/0 or outside the supported set, or a raw int cast without validation.","commonSituations":"Decoding stroke packet data from another application or older ISF writer using an unsupported Gorilla encoding; custom decompression code caching an invalid enum; uninitialized encoding fields.","solutions":["Validate the encoding type against known GorillaEncodingType members before calling Uncompress.","Default Unknown encodings to a concrete supported member if the data format allows (e.g. re-encode as OneByte).","Treat payloads with unsupported encodings as corrupt ISF: catch ArgumentException and reject or re-acquire the ink data.","Verify the producer wrote a supported encoding; convert the data with a compatible library version if needed."],"exampleFix":"// before\ncodec.Uncompress(encodingFromHeader, reader, count, out output);\n// after\nif (encodingFromHeader == GorillaEncodingType.Unknown)\n    throw new InvalidDataException(\"ISF uses unsupported Gorilla encoding\");\ncodec.Uncompress(encodingFromHeader, reader, count, out output);","handlingStrategy":"try-catch","validationCode":"if (encodingType == GorillaEncodingType.Unknown || !Enum.IsDefined(typeof(GorillaEncodingType), encodingType))\n    throw new InvalidDataException(\"Unsupported Gorilla encoding in ISF payload\");","typeGuard":"bool IsDecodable(GorillaEncodingType t) => Enum.IsDefined(typeof(GorillaEncodingType), t) && t != GorillaEncodingType.Unknown;","tryCatchPattern":"try { codec.Uncompress(encodingType, reader, units, out output); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Uncompress\")) { /* treat ink data as corrupt; re-import or fail gracefully */ }","preventionTips":["Whitelist supported GorillaEncodingType values before decompressing external data.","Check the producer's ink format/version when payloads come from other applications.","Log the offending encoding value to aid diagnosis of nonstandard ISF sources."],"tags":["ink","gorilla-codec","enum","decompression"],"backgroundTag":"invalid-enum-value","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"}