dotnet/wpf · error · ArgumentException

ISF size is larger than maximum stream size

Error message

ISF size is larger than maximum stream size

What it means

DecodeAsISF validates that each decoded attribute size (cb) fits within the caller-provided maximumStreamSize budget. When the size prefix read from the stream exceeds the remaining allowed size, it throws ArgumentException with the message 'ISF size is larger than maximum stream size'. This protects against malformed or hostile streams claiming huge sizes.

Solutions

  1. Pass the full accurate stream length as maximumStreamSize
  2. Validate the ISF source integrity before decoding
  3. Wrap the decode in try-catch and reject the input as corrupt
  4. Regenerate the ISF from original ink data if available

Example fix

// before
DrawingAttributeSerializer.DecodeAsISF(stream, guidList, (uint)stream.Length / 2); // budget too small
// after
uint maxSize = (uint)stream.Length;
DrawingAttributeSerializer.DecodeAsISF(stream, guidList, maxSize);
Defensive patterns

Strategy: try-catch

Validate before calling

// caller: ensure the budget covers the stream
uint maxSize = stream.CanSeek ? (uint)stream.Length : uint.MaxValue;

Try / catch

try { DrawingAttributeSerializer.DecodeAsISF(stream, guidList, maxSize); }
catch (ArgumentException) { /* mark input corrupt; reject */ }

Prevention

When it happens

Trigger: Decoding a DrawingAttributes ISF stream whose first size field (cb) is greater than the maximumStreamSize passed to DecodeAsISF — typically a corrupt, truncated, or maliciously crafted stream.

Common situations: Loading ISF from untrusted sources; files truncated in transit; passing a too-small maximumStreamSize when the caller computes the budget incorrectly.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/DrawingAttributeSerializer.cs:134

            double stylusHeight = DrawingAttributeSerializer.V1PenHeightWhenHeightIsMissing;
            uint rasterOperation = DrawingAttributeSerializer.RasterOperationDefaultV1;
            int transparency = DrawingAttributeSerializer.TransparencyDefaultV1;
            bool widthIsSetInISF = false; //did we find KnownIds.Width?
            bool heightIsSetInISF = false; //did we find KnownIds.Height?


            uint cbTotal = maximumStreamSize;
            while (maximumStreamSize > 0)
            {
                KnownTagCache.KnownTagIndex tag;
                uint uiTag;
                // First read the tag
                uint cb = SerializationHelper.Decode (stream, out uiTag);
                tag = (KnownTagCache.KnownTagIndex)uiTag;

                if (maximumStreamSize < cb)
                {
                    throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("ISF size is larger than maximum stream size"));
                }

                maximumStreamSize -= cb;

                // Get the guid based on the tag
                Guid guid = guidList.FindGuid (tag);
                if (guid == Guid.Empty)
                {
                    throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Drawing Attribute tag embedded in ISF stream does not match guid table"));
                }

                uint dw = 0;

                if (KnownIds.PenTip == guid)
                {
                    cb = SerializationHelper.Decode (stream, out dw);
                    penTip = (PenTip)dw;
                    if (!PenTipHelper.IsDefined(penTip))

View on GitHub (pinned to 81131a70a4)