{"record":{"id":"7d1097ee30c3a1b5","repo":"dotnet/wpf","slug":"invalid-huffman-encoded-data","errorCode":null,"errorMessage":"invalid huffman encoded data","messagePattern":"invalid huffman encoded data","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/HuffCodec.cs","lineNumber":237,"sourceCode":"                // return the bit count read from stream\n                return;\n            }\n            else if (prefIndex == _huffBits.GetSize())\n            {\n                // This is the special prefix for extra data.\n                // Decode the prefix first\n                int extra2 = 0;\n                int extra2Ignored = 0;\n                Decode(ref extra2, ref extra2Ignored, reader);\n                extra = extra2;\n                \n                // Following is the actual data\n                int data2 = 0;\n                Decode(ref data2, ref extra2Ignored, reader);\n                data = data2;\n                return;\n            }\n            throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage(\"invalid huffman encoded data\"));\n        }\n\n        /// <summary>\n        /// Privates\n        /// </summary>\n        private HuffBits    _huffBits;\n        private uint[]      _mins = new uint[MaxBAASize];\n\n        /// <summary>\n        /// Private statics\n        /// </summary>\n        private const byte MaxBAASize = 10;\n\n        /// <summary>\n        /// Private helper class\n        /// </summary>\n        private class HuffBits\n        {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/HuffCodec.cs#L219-L255","documentation":"HuffCodec.Decode decompresses huffman-encoded data inside ISF. If the bit stream does not decode to a recognized value pattern, the codec cannot produce a valid result and throws ArgumentException('invalid huffman encoded data'). This indicates the compressed payload does not match the huffman tables used to decode it.","triggerScenarios":"Uncompressing an ISF packet whose huffman-coded bytes were corrupted, produced with a different codec/table than the decoder found (FindCodec mismatch), or truncated mid-symbol.","commonSituations":"Opening ISF files damaged by storage/transfer, hand-edited ink payloads, or streams written by a writer using codec indices the reader maps to a different huffman table.","solutions":["Re-obtain the ISF stream from the original source; treat the current payload as corrupt.","Confirm the codec index in the ISF header resolves to the same huffman codec used at write time.","Validate stream length vs expected data size before decompression.","Catch ArgumentException in Uncompress/DecodeAsISF paths and skip the affected draw attribute rather than crashing."],"exampleFix":"// before\nbyte[] data = huffModule.Uncompress(reader); // throws on bad data\n// after\ntry { byte[] data = huffModule.Uncompress(reader); }\ncatch (ArgumentException) { /* mark stream corrupt, fall back to uncompressed path */ }","handlingStrategy":"try-catch","validationCode":"// verify stream can supply expected compressed length\nif (reader.BaseStream.Length - reader.BaseStream.Position < declaredSize) throw new InvalidDataException();","typeGuard":null,"tryCatchPattern":"try { data = huffCodec.Uncompress(reader); }\ncatch (ArgumentException ex) { MarkStreamCorrupt(ex); return null; }","preventionTips":["Verify ISF integrity (checksum/length) before decode","Avoid hand-editing ISF bytes","Log InnerException to identify the failing symbol"],"tags":["ink","isf","huffman","decompression","corrupt-data"],"backgroundTag":"invalid-argument-format","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"}