{"record":{"id":"0c9262bbb1dee1a9","repo":"dotnet/wpf","slug":"sr-invalidstream","errorCode":null,"errorMessage":"SR.InvalidStream","messagePattern":"SR\\.InvalidStream","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/InkSerializer.cs","lineNumber":342,"sourceCode":"                throw new InvalidOperationException(ISFDebugMessage(\"ISF decoder cannot operate on non-empty ink container\"));\n            }\n#if OLD_ISF\n            //\n            // store a compressor reference at this scope, if it is needed (if there is a compresson header) and\n            // therefore instanced during this routine, we will dispose of it\n            // in the finally block\n            //\n            Compressor compressor = null;\n\n            try\n            {\n#endif\n\n            // First read the isfTag\n            uint uiTag;\n            uint localBytesDecoded = SerializationHelper.Decode(inputStream, out uiTag);\n            if (0x00 != uiTag)\n                throw new ArgumentException(SR.InvalidStream);\n\n            // Now read the size of the stream\n            localBytesDecoded = SerializationHelper.Decode(inputStream, out remainingBytesInStream);\n            ISFDebugTrace(\"Decoded Stream Size in Bytes: \" + remainingBytesInStream.ToString());\n            if (0 == remainingBytesInStream)\n                return;\n\n            while (0 < remainingBytesInStream)\n            {\n                bytesDecodedInCurrentTag = 0;\n\n                // First read the isfTag\n                localBytesDecoded = SerializationHelper.Decode(inputStream, out uiTag);\n                isfTag = (KnownTagCache.KnownTagIndex)uiTag;\n                if (remainingBytesInStream >= localBytesDecoded)\n                    remainingBytesInStream -= localBytesDecoded;\n                else\n                {","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/InkSerializer.cs#L324-L360","documentation":"DecodeRawISF throws this ArgumentException when the first uint decoded from the ISF input stream is not the expected ISF tag value (0x00). It is a guard that the byte stream actually begins with a valid ISF structure rather than arbitrary bytes. The library throws instead of silently misparsing corrupt or non-ISF data.","triggerScenarios":"Calling StrokeCollectionSerializer.DecodeISF (or InkSerializer.Decode) on a stream whose first 4 bytes do not decode to ISF tag 0x00 — e.g. a stream positioned mid-file, a PNG/GIF passed as ISF, or an empty/garbage byte array.","commonSituations":"Passing a file stream opened without rewinding to position 0 after writing; feeding a serialized format other than ISF (e.g. base64 of an image); loading ISF saved by a different/older ink implementation with a different header.","solutions":["Verify the stream is positioned at the start of the ISF data (stream.Position = 0 / seek to 0 before decoding).","Confirm the data is actually ISF (e.g. produced by StrokeCollectionSerializer.Save) and not another format such as GIF or PNG.","Regenerate the ISF payload from the source application to rule out truncation or corruption in transit.","Wrap decoding in try/catch for ArgumentException and treat the stream as invalid/unparseable ink."],"exampleFix":"// before\nvar ink = StrokeCollectionSerializer.DecodeISF(someStream);\n// after\nsomeStream.Position = 0;\nif (!isPlausibleIsf(someStream)) throw new InvalidDataException(\"Not ISF data\");\nsomeStream.Position = 0;\nvar ink = StrokeCollectionSerializer.DecodeISF(someStream);","handlingStrategy":"validation","validationCode":"bool IsPlausibleIsf(Stream s) { if (s.Length < 8) return false; long pos = s.Position; s.Position = 0; var buf = new byte[8]; s.Read(buf, 0, 8); s.Position = pos; return buf[0] == 0; }","typeGuard":null,"tryCatchPattern":"try { stream.Position = 0; return StrokeCollectionSerializer.DecodeISF(stream); } catch (ArgumentException ex) { logger.Warn(ex, \"Invalid ISF stream header\"); return null; }","preventionTips":["Always seek the stream to position 0 before decoding.","Only decode ISF produced by StrokeCollectionSerializer.Save or another known ISF writer.","Never pass image files (GIF/PNG) directly as ISF without extraction.","Unit-test decode round-trips with saved ink fixtures."],"tags":["ink","isf","deserialization","wpf"],"backgroundTag":"invalid-argument-format","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"}