{"record":{"id":"ccce6b43f676bd09","repo":"dotnet/wpf","slug":"sr-corrupteddata","errorCode":null,"errorMessage":"SR.CorruptedData","messagePattern":"SR\\.CorruptedData","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Certificate.cs","lineNumber":99,"sourceCode":"        //------------------------------------------------------\n        /// <summary>\n        /// Certificate to associate with this Certificate Part\n        /// </summary>\n        /// <value></value>\n        /// <exception cref=\"FileFormatException\">stream is too large</exception>\n        internal X509Certificate2 GetCertificate()\n        {\n            // lazy init\n            if (_certificate == null)\n            {\n                // obtain from the part\n                using (Stream s = _part.GetStream())\n                {\n                    if (s.Length > 0)\n                    {\n                        // throw if stream is beyond any reasonable length\n                        if (s.Length > _maximumCertificateStreamLength)\n                            throw new FileFormatException(SR.CorruptedData);\n\n                        // X509Certificate constructor desires a byte array\n                        Byte[] byteArray = new Byte[s.Length];\n                        PackagingUtilities.ReliableRead(s, byteArray, 0, (int)s.Length);\n                        _certificate = X509CertificateLoader.LoadCertificate(byteArray);\n                    }\n                }\n            }\n            return _certificate;\n        }\n\n        internal void SetCertificate(X509Certificate2 certificate)\n        {\n            ArgumentNullException.ThrowIfNull(certificate);\n\n            _certificate = certificate;\n\n            // persist to the part","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Certificate.cs#L81-L117","documentation":"CertificatePart.GetCertificate throws this FileFormatException with SR.CorruptedData when the X.509 certificate bytes read from the certificate part cannot be constructed into an X509Certificate2 — the part's data is corrupt or not a valid certificate stream.","triggerScenarios":"Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Certificate.cs:99 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the certificate part data in the package is not corrupted or oversized","Re-export the digital signature/certificate part with valid X.509 data","Catch FileFormatException when opening untrusted XPS packages and surface a corruption error"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}