{"record":{"id":"7afd4ee92524d707","repo":"dotnet/wpf","slug":"invalid-argument-passed-to-reliableread","errorCode":null,"errorMessage":"Invalid argument passed to ReliableRead","messagePattern":"Invalid argument passed to ReliableRead","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/InkSerializer.cs","lineNumber":1210,"sourceCode":"                throw new ArgumentException(ISFDebugMessage(\"Invalid ISF data\"),nameof(strm));\n\n            return cbSize;\n        }\n\n        /// <summary>\n        /// ReliableRead\n        /// </summary>\n        /// <param name=\"stream\"></param>\n        /// <param name=\"buffer\"></param>\n        /// <param name=\"requestedCount\"></param>\n        /// <returns></returns>\n        internal static uint ReliableRead(Stream stream, byte[] buffer, uint requestedCount)\n        {\n            if (stream == null ||\n                buffer == null ||\n                requestedCount > buffer.Length)\n            {\n                throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage(\"Invalid argument passed to ReliableRead\"));\n            }\n\n            // let's read the whole block into our buffer\n            uint totalBytesRead = 0;\n            while (totalBytesRead < requestedCount)\n            {\n                int bytesRead = stream.Read(buffer,\n                                (int)totalBytesRead,\n                                (int)(requestedCount - totalBytesRead));\n                if (bytesRead == 0)\n                {\n                    break;\n                }\n                totalBytesRead += (uint)bytesRead;\n            }\n            return totalBytesRead;\n        }\n","sourceCodeStart":1192,"sourceCodeEnd":1228,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/InkSerializer.cs#L1192-L1228","documentation":"ReliableRead validates its inputs before reading from the stream: a null stream, null buffer, or a requestedCount larger than the buffer length causes this ArgumentException. It is an internal API-contract violation rather than a data-corruption signal — a caller passed inconsistent arguments.","triggerScenarios":"Internal ISF decode paths calling ReliableRead with a buffer smaller than the block size declared in the ISF header (e.g. after a size field was decoded as a huge/garbage value), or null stream/buffer.","commonSituations":"Mostly seen when a corrupt ISF header yields a bogus count passed through to ReliableRead; rare direct-internal misuse when custom code drives the deserialization pipeline.","solutions":["Treat this as a symptom of corrupt ISF: check the blob's header bytes for garbage size values","Re-serialize the ink payload rather than repairing bytes","Ensure the Stream passed to ink deserialization is readable, non-null, and positioned at 0","If reproducing internally, size the read buffer to at least the decoded block count"],"exampleFix":"// before\nvar buffer = new byte[64];\nReliableRead(stream, buffer, declaredBlockSize); // throws if declaredBlockSize > 64\n// after\nvar buffer = new byte[Math.Max(declaredBlockSize, 64)];\nReliableRead(stream, buffer, declaredBlockSize);","handlingStrategy":"type-guard","validationCode":"if (stream == null || !stream.CanRead) throw new InvalidOperationException(\"stream must be readable\");\nstream.Position = 0;","typeGuard":"static bool IsReadable(Stream s) => s != null && s.CanRead;","tryCatchPattern":"try { strokes = LoadIsf(stream); }\ncatch (ArgumentException ex) { throw new InvalidDataException(\"ISF header declared an impossible block size (likely corrupt data)\", ex); }","preventionTips":["Pass a readable, non-null, position-0 stream to ink deserialization","Size read buffers to at least the decoded block count","When this fires, suspect a corrupt ISF header upstream","Never let user-controlled sizes index or size buffers directly"],"tags":["ink","isf","argument-validation","wpf"],"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-22T01:17:13.364Z"}