dotnet/wpf · error · ArgumentException
bogus GorillaEncodingType passed to Uncompress
Error message
bogus GorillaEncodingType passed to Uncompress
What it means
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.
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.
Example fix
// before
codec.Uncompress(encodingFromHeader, reader, count, out output);
// after
if (encodingFromHeader == GorillaEncodingType.Unknown)
throw new InvalidDataException("ISF uses unsupported Gorilla encoding");
codec.Uncompress(encodingFromHeader, reader, count, out output); Defensive patterns
Strategy: try-catch
Validate before calling
if (encodingType == GorillaEncodingType.Unknown || !Enum.IsDefined(typeof(GorillaEncodingType), encodingType))
throw new InvalidDataException("Unsupported Gorilla encoding in ISF payload"); Type guard
bool IsDecodable(GorillaEncodingType t) => Enum.IsDefined(typeof(GorillaEncodingType), t) && t != GorillaEncodingType.Unknown;
Try / catch
try { codec.Uncompress(encodingType, reader, units, out output); }
catch (ArgumentException ex) when (ex.Message.Contains("Uncompress")) { /* treat ink data as corrupt; re-import or fail gracefully */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- bogus GorillaEncodingType passed to compress
- bogus GorillaEncodingType passed to GetDataFromReader
- Decompression of packet data failed.
- input or compressed data was null in Compress
- invalid huffman encoded data
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e2a9a11c20f969ff.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/GorillaCodec.cs:623
bitsToWrite = Native.BitsPerShort;
//shorts are decoded as unsigned values, no mask required
bitMask = 0;
break;
}
case GorillaEncodingType.Byte:
{
if (bitCount == 0)
{
bitCount = Native.BitsPerByte;
}
bitsToWrite = Native.BitsPerByte;
//bytes are decoded as unsigned values, no mask required
bitMask = 0;
break;
}
default:
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("bogus GorillaEncodingType passed to Uncompress"));
}
}
List<byte> output = new List<byte>((bitsToWrite / 8) * unitsToDecode);
BitStreamWriter writer = new BitStreamWriter(output);
uint bitData = 0;
while (!reader.EndOfStream && unitsToDecode > 0)
{
//we're going to cast to an uint anyway, just read as one
bitData = reader.ReadUInt32(bitCount);
// Construct the item
bitData = ((bitData & bitMask) != 0) ? bitMask | bitData : bitData;
writer.WriteReverse(bitData, bitsToWrite);
unitsToDecode--;
}
return output.ToArray();
}View on GitHub (pinned to 81131a70a4)