{"record":{"id":"dfe7950e6d6aff15","repo":"dotnet/wpf","slug":"sr-uselicensestreamcorrupt","errorCode":null,"errorMessage":"SR.UseLicenseStreamCorrupt","messagePattern":"SR\\.UseLicenseStreamCorrupt","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs","lineNumber":687,"sourceCode":"        {\n            utf8Reader.BaseStream.Seek(0, SeekOrigin.Begin);\n\n            //\n            // The stream begins with a header of the following format:\n            //\n            //      Int32   headerLength\n            //      Int32   userNameLen\n            //      Byte    userName[userNameLen]\n            //\n            // ... and then continues with:\n            //\n            //      In32    useLicenseLen\n            //      Byte    useLicense[useLicenseLen];\n            //\n            Int32 headerLength = utf8Reader.ReadInt32();\n            if (headerLength < UseLicenseStreamLengthMin)\n            {\n                throw new FileFormatException(SR.UseLicenseStreamCorrupt);\n            }\n\n            //\n            // The type-prefixed user name string (e.g., \"windows:domain\\alias\") was\n            // treated as a sequence of little-Endian UTF-16 characters. The octet\n            // sequence representing those characters in that encoding were Base-64 \n            // encoded. The resulting character string was then UTF-8 encoded. The\n            // resulting byte-length-prefixed UTF-8 byte sequence is what was stored\n            // in the use license stream.\n            //\n            string base64UserName = ReadLengthPrefixedString(utf8Reader, Encoding.UTF8, UserNameLengthMax);\n            byte[] userNameBytes = Convert.FromBase64String(base64UserName);\n\n            string typePrefixedUserName =\n                        new string(\n                            _unicodeEncoding.GetChars(userNameBytes)\n                            );\n","sourceCodeStart":669,"sourceCodeEnd":705,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs#L669-L705","documentation":"LoadUseLicenseAndUserFromStream reads an Int32 header length and throws FileFormatException with SR.UseLicenseStreamCorrupt if it is below UseLicenseStreamLengthMin. This means the use-license stream in the compound file does not match the expected binary layout and is considered corrupt or truncated.","triggerScenarios":"Reading a use-license stream whose leading Int32 is smaller than UseLicenseStreamLengthMin; a truncated/corrupted compound file; a stream written by an incompatible or pre-release format version.","commonSituations":"Manually edited or damaged XPS/protected documents; files written by an older WPF RM implementation; I/O truncation when the package was saved; tampering attempts.","solutions":["Verify the document integrity / regenerate the protected package from source","Open the file in the application that produced it to re-save a valid use-license stream","Check the file was not truncated during transfer (compare sizes/checksums)","Catch FileFormatException and treat the document as corrupt, prompting re-acquisition of licenses"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// peek header before full load\nusing var br = new BinaryReader(stream, Encoding.UTF8, true);\nint len = br.ReadInt32();\nif (len < UseLicenseStreamLengthMin) /* treat as corrupt */;","typeGuard":"bool IsPlausibleUseLicenseStream(Stream s) { if (!s.CanRead) return false; long p = s.Position; using var br = new BinaryReader(s, Encoding.UTF8, true); int len; try { len = br.ReadInt32(); } catch { return false; } finally { s.Position = p; } return len >= UseLicenseStreamLengthMin; }","tryCatchPattern":"try { transform.LoadUseLicense(stream); } catch (FileFormatException) { /* document corrupt: re-acquire license or regenerate package */ }","preventionTips":["Verify package integrity (checksum/size) after transfers","Do not hand-edit protected documents","Keep producer and consumer on compatible RM format versions"],"tags":["wpf","rights-management","file-format","corruption"],"backgroundTag":"schema-validation-failed","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"}