dotnet/wpf · error · ArgumentException

invalid codec computed

Error message

invalid codec computed

What it means

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.

Solutions

  1. Ensure the huffman codec tables (DtXf) are decoded/registered before FindCodec is called.
  2. Verify the ISF stream was written by a version whose codec count is compatible with the reader.
  3. Validate the codec index read from the stream against available codecs before lookup.
  4. Treat streams exceeding supported codec counts as invalid and reject them at load.

Example fix

// before
var codec = huffModule.FindCodec(rawIndex); // throws if out of range
// after
if (rawIndex < huffModule.CodecCount + AlgoModule.DefaultBAACount)
{
    var codec = huffModule.FindCodec(rawIndex);
}
else { /* unsupported stream, abort decode */ }
Defensive patterns

Strategy: validation

Validate before calling

bool CodecSupported(int idx, int customCount) => idx >= 0 && idx < customCount + AlgoModule.DefaultBAACount;

Type guard

static bool IsValidCodecIndex(uint codec, int customCount) => codec < (uint)(customCount + AlgoModule.DefaultBAACount);

Try / catch

try { var c = huffModule.FindCodec(idx); }
catch (ArgumentException) { RejectStream("unknown huffman codec"); }

Prevention

When it happens

Trigger: 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).

Common situations: Reader sessions that skipped loading the huffman transform tables, ISF from newer writers with more codecs, corrupted stream headers.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/2d69b891c8be3eed. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/HuffModule.cs:59

            byte codec = (byte)(algoData & 0x1f);
            //unused
            //if ((0x20 & algoData) != 0)
            //{
            //    int iLookup = (algoData & 0x1f);
            //    if ((iLookup > 0) && (iLookup <= _lookupList.Count))
            //    {
            //        codec = _lookupList[iLookup - 1].Byte;
            //    }
            //}

            if (codec < AlgoModule.DefaultBAACount)
            {
                return GetDefCodec((uint)codec);
            }
            
            if ((int)codec >= _huffCodecs.Count + AlgoModule.DefaultBAACount)
            {
                throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("invalid codec computed"));
            }
            return _huffCodecs[(int)(codec - AlgoModule.DefaultBAACount)];
        }

        /// <summary>
        /// FindDtXf
        /// </summary>
        /// <param name="algoData"></param>
        internal DataXform FindDtXf(byte algoData)
        {
            //unused
            //if ((0x20 & algoData) != 0)
            //{
            //    int lookupIndex = (int)(algoData & 0x1f);
            //    if ((lookupIndex > 0) && (lookupIndex < _lookupList.Count))
            //    {
            //        return _lookupList[lookupIndex].DeltaDelta;
            //    }

View on GitHub (pinned to 81131a70a4)