dotnet/wpf · error · ArgumentException
ISF size if greater then maximum stream size
Error message
ISF size if greater then maximum stream size
What it means
For variable-size attribute payloads, DecodeAsISF reads a length prefix (adds one via cbInSize++), then checks that the resulting payload size still fits within the remaining maximumStreamSize. If cbInSize exceeds it, ArgumentException with 'ISF size if greater then maximum stream size' is thrown, protecting against oversized/corrupt size fields.
Solutions
- Pass the true full stream length as maximumStreamSize
- Validate stream integrity/length before decoding
- Try-catch the decode and treat failure as corrupt input
- Regenerate the ISF from the original ink source
Example fix
// before uint budget = 1024; // arbitrary DrawingAttributeSerializer.DecodeAsISF(stream, guidList, budget); // after uint budget = (uint)stream.Length; // real stream size DrawingAttributeSerializer.DecodeAsISF(stream, guidList, budget);
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check budget
if (!stream.CanSeek || stream.Length == 0) throw new InvalidDataException("empty or non-seekable ISF stream"); Try / catch
try { DrawingAttributeSerializer.DecodeAsISF(stream, guidList, maxSize); }
catch (ArgumentException) { /* treat stream as corrupt; reject or quarantine */ } Prevention
- Pass the real stream length as maximumStreamSize
- Checksum and length-validate ISF before decoding
- Fuzz-test your ISF loading path with malformed inputs
- Regenerate ISF rather than attempting byte-level repairs
When it happens
Trigger: Decoding ISF where a size prefix (plus one byte) exceeds the remaining maximumStreamSize — truncated files, malicious streams with inflated lengths, or a caller-supplied maximumStreamSize smaller than the real data.
Common situations: Untrusted ISF input (fuzzing/malware analysis); files damaged in transfer; incorrectly computed stream budgets in calling code.
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
- ISF size is larger than maximum stream size
- SR.Image_StreamRead
- SR.Image_StreamWrite
- SR.Invalid_isfData_Length
- Cannot initialize compressor.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/4ab0a5ed22620b9a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/DrawingAttributeSerializer.cs:218
cb = SerializationHelper.Decode (stream, out dw);
_size = (double)dw;
maximumStreamSize -= cb;
if (maximumStreamSize > 0)
{
cb = SerializationHelper.Decode (stream, out dw);
maximumStreamSize -= cb;
if (KnownTagCache.KnownTagIndex.Mantissa == (KnownTagCache.KnownTagIndex)dw)
{
uint cbInSize;
// First thing that is in there is maximumStreamSize of the data
cb = SerializationHelper.Decode (stream, out cbInSize);
maximumStreamSize -= cb;
// in maximumStreamSize is one more than the decoded no
cbInSize++;
if (cbInSize > maximumStreamSize)
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("ISF size if greater then maximum stream size"));
}
byte[] in_data = new byte[cbInSize];
uint bytesRead = (uint) stream.Read (in_data, 0, (int)cbInSize);
if (cbInSize != bytesRead)
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Read different size from stream then expected"));
}
byte[] out_buffer = Compressor.DecompressPropertyData (in_data);
using (MemoryStream localStream = new MemoryStream(out_buffer))
using (BinaryReader rdr = new BinaryReader(localStream))
{
short sFraction = rdr.ReadInt16();
_size += (double)(sFraction / DrawingAttributes.StylusPrecision);
maximumStreamSize -= cbInSize;
}View on GitHub (pinned to 81131a70a4)