{"record":{"id":"0733436116c51ba1","repo":"dotnet/wpf","slug":"bogus-gorillaencodingtype-passed-to-getdatafromreader","errorCode":null,"errorMessage":"bogus GorillaEncodingType passed to GetDataFromReader","messagePattern":"bogus GorillaEncodingType passed to GetDataFromReader","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/GorillaCodec.cs","lineNumber":478,"sourceCode":"        private int GetDataFromReader(BitStreamReader reader, GorillaEncodingType type)\n        {\n            switch (type)\n            {\n                case GorillaEncodingType.Int:\n                    {\n                        return (int)reader.ReadUInt32Reverse(Native.BitsPerInt);\n                    }\n                case GorillaEncodingType.Short:\n                    {\n                        return (int)reader.ReadUInt16Reverse(Native.BitsPerShort);\n                    }\n                case GorillaEncodingType.Byte:\n                    {\n                        return (int)reader.ReadByte(Native.BitsPerByte);\n                    }\n                default:\n                    {\n                        throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage(\"bogus GorillaEncodingType passed to GetDataFromReader\"));\n                    }\n            }\n        }\n\n\n        /// <summary>\n        /// Uncompress - uncompress a byte[] into an int[] of point data (x,x,x,x,x)\n        /// </summary>\n        /// <param name=\"bitCount\">The number of bits each element uses in input</param>\n        /// <param name=\"input\">compressed data</param>\n        /// <param name=\"inputIndex\">index to begin decoding at</param>\n        /// <param name=\"dtxf\">data xf, can be null</param>\n        /// <param name=\"outputBuffer\">output buffer that is prealloc'd to write to</param>\n        /// <param name=\"outputBufferIndex\">the index of the output buffer to write to</param>\n        internal uint Uncompress(int bitCount, byte[] input, int inputIndex, DeltaDelta dtxf, int[] outputBuffer, int outputBufferIndex)\n        {\n            ArgumentNullException.ThrowIfNull(input);\n            ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(inputIndex, input.Length);","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/GorillaCodec.cs#L460-L496","documentation":"GorillaCodec.GetDataFromReader decodes a single unit according to the GorillaEncodingType; an unrecognized type hits the default case and throws ArgumentException with this message. The decoder supports only the enum members it has switch cases for, so an invalid type is rejected defensively.","triggerScenarios":"Calling GetDataFromReader with an invalid GorillaEncodingType (typically Unknown/0 or an out-of-range int cast), often an encoding value read from an ISF header that was never validated before use.","commonSituations":"Decoding ISF stroke data produced by a producer writing an unsupported encoding value; custom decode loops caching an enum read from bytes without mapping; uninitialized enum fields.","solutions":["Validate the encoding type read from the ISF data before calling GetDataFromReader; reject or default Unknown values.","Map raw int encodings through a whitelist switch to valid GorillaEncodingType members.","If the payload is external, treat this as corrupt ISF: catch ArgumentException and reject or re-import the ink data.","Check the producing application/version for nonstandard Gorilla encoding types."],"exampleFix":"// before\ncodec.GetDataFromReader(reader, parsedEncoding, out data);\n// after\nif (!Enum.IsDefined(typeof(GorillaEncodingType), parsedEncoding) || parsedEncoding == GorillaEncodingType.Unknown)\n    throw new InvalidDataException(\"Unsupported ISF encoding type\");\ncodec.GetDataFromReader(reader, parsedEncoding, out data);","handlingStrategy":"try-catch","validationCode":"if (!Enum.IsDefined(typeof(GorillaEncodingType), encodingType) || encodingType == GorillaEncodingType.Unknown)\n    throw new InvalidDataException(\"ISF data uses an unsupported Gorilla encoding type\");","typeGuard":"bool IsDecodable(GorillaEncodingType t) => Enum.IsDefined(typeof(GorillaEncodingType), t) && t != GorillaEncodingType.Unknown;","tryCatchPattern":"try { data = codec.GetDataFromReader(reader, encodingType); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"GetDataFromReader\")) { /* reject payload as corrupt ISF */ }","preventionTips":["Validate encoding values read from ISF headers before decoding.","Reject unknown encodings early with a clear 'corrupt/unsupported ISF' error.","Keep enum values in one authoritative mapping to avoid ad-hoc casts."],"tags":["ink","gorilla-codec","enum","decoding"],"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"}