{"record":{"id":"2d69b891c8be3eed","repo":"dotnet/wpf","slug":"invalid-codec-computed","errorCode":null,"errorMessage":"invalid codec computed","messagePattern":"invalid codec computed","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/HuffModule.cs","lineNumber":59,"sourceCode":"            byte codec = (byte)(algoData & 0x1f);\n            //unused\n            //if ((0x20 & algoData) != 0)\n            //{\n            //    int iLookup = (algoData & 0x1f);\n            //    if ((iLookup > 0) && (iLookup <= _lookupList.Count))\n            //    {\n            //        codec = _lookupList[iLookup - 1].Byte;\n            //    }\n            //}\n\n            if (codec < AlgoModule.DefaultBAACount)\n            {\n                return GetDefCodec((uint)codec);\n            }\n            \n            if ((int)codec >= _huffCodecs.Count + AlgoModule.DefaultBAACount)\n            {\n                throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage(\"invalid codec computed\"));\n            }\n            return _huffCodecs[(int)(codec - AlgoModule.DefaultBAACount)];\n        }\n\n        /// <summary>\n        /// FindDtXf\n        /// </summary>\n        /// <param name=\"algoData\"></param>\n        internal DataXform FindDtXf(byte algoData)\n        {\n            //unused\n            //if ((0x20 & algoData) != 0)\n            //{\n            //    int lookupIndex = (int)(algoData & 0x1f);\n            //    if ((lookupIndex > 0) && (lookupIndex < _lookupList.Count))\n            //    {\n            //        return _lookupList[lookupIndex].DeltaDelta;\n            //    }","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/HuffModule.cs#L41-L77","documentation":"HuffModule.FindCodec maps a codec index from the ISF stream to an available huffman codec. Indices beyond DefaultBAACount plus the custom codecs loaded (_huffCodecs.Count) do not exist, so the module throws ArgumentException('invalid codec computed'). The stream references a codec that was never defined for this decode session.","triggerScenarios":"Decoding ISF where the stream's codec index >= _huffCodecs.Count + AlgoModule.DefaultBAACount - typically data written with codecs not loaded, a corrupt header value, or out-of-order decoding (FindDtXf tables not yet registered).","commonSituations":"Reader sessions that skipped loading the huffman transform tables, ISF from newer writers with more codecs, corrupted stream headers.","solutions":["Ensure the huffman codec tables (DtXf) are decoded/registered before FindCodec is called.","Verify the ISF stream was written by a version whose codec count is compatible with the reader.","Validate the codec index read from the stream against available codecs before lookup.","Treat streams exceeding supported codec counts as invalid and reject them at load."],"exampleFix":"// before\nvar codec = huffModule.FindCodec(rawIndex); // throws if out of range\n// after\nif (rawIndex < huffModule.CodecCount + AlgoModule.DefaultBAACount)\n{\n    var codec = huffModule.FindCodec(rawIndex);\n}\nelse { /* unsupported stream, abort decode */ }","handlingStrategy":"validation","validationCode":"bool CodecSupported(int idx, int customCount) => idx >= 0 && idx < customCount + AlgoModule.DefaultBAACount;","typeGuard":"static bool IsValidCodecIndex(uint codec, int customCount) => codec < (uint)(customCount + AlgoModule.DefaultBAACount);","tryCatchPattern":"try { var c = huffModule.FindCodec(idx); }\ncatch (ArgumentException) { RejectStream(\"unknown huffman codec\"); }","preventionTips":["Decode DtXf/codec tables before data that references them","Check writer/reader version compatibility","Clamp or reject out-of-range codec indices in untrusted input"],"tags":["ink","isf","huffman","codec","decoding"],"backgroundTag":"invalid-argument-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"}