{"record":{"id":"8869860eac45591b","repo":"dotnet/wpf","slug":"sr-packagesignaturecorruption-xmlsignaturemanifest","errorCode":null,"errorMessage":"SR.PackageSignatureCorruption","messagePattern":"SR\\.PackageSignatureCorruption","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlSignatureManifest.cs","lineNumber":146,"sourceCode":"                    {\n                        foreach (PackageRelationshipSelector relationshipSelector in partManifestEntry.RelationshipSelectors)\n                            relationshipManifest.Add(relationshipSelector);\n                    }\n                    else\n                        partManifest.Add(partManifestEntry.Uri);\n\n                    // return the manifest entry to be used for hashing\n                    partEntryManifest.Add(partManifestEntry);\n\n                    referenceCount++;\n                }\n                else\n                    throw new XmlException(SR.Format(SR.UnexpectedXmlTag, reader.Name));\n            }\n\n            // XmlDSig xsd requires at least one <Reference> tag\n            if (referenceCount == 0)\n                throw new XmlException(SR.PackageSignatureCorruption);\n        }\n\n        /// <summary>\n        /// Parse the DigestMethod tag\n        /// </summary>\n        /// <param name=\"reader\"></param>\n        private static string ParseDigestAlgorithmTag(XmlReader reader)\n        {\n            // verify namespace and lack of attributes\n            if (PackagingUtilities.GetNonXmlnsAttributeCount(reader) > 1\n                || !string.Equals(reader.NamespaceURI, SignedXml.XmlDsigNamespaceUrl, StringComparison.Ordinal)\n                || reader.Depth != 3)\n                throw new XmlException(SR.XmlSignatureParseError);\n\n            // get the Algorithm attribute\n            string hashAlgorithm = null;\n            if (reader.HasAttributes)\n            {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlSignatureManifest.cs#L128-L164","documentation":"System.IO.Packaging throws this XmlException while parsing a PackageDigitalSignature's XMLDSig manifest when the <SignedInfo>/<References> section contains no <Reference> element at all. The XMLDSig schema mandates at least one Reference per signature, so a signature without any is structurally corrupt and cannot be verified.","triggerScenarios":"Opening or verifying a package signature whose OpcSignature/SignedInfo XML has zero <Reference> child elements; ParseManifest counts references while reading and throws when referenceCount == 0 after the element loop.","commonSituations":"Hand-edited or tool-mangled signature XML inside an OPC package (e.g. a .docx or .oxps re-zipped incorrectly), a signature generated by a non-Open Packaging Conventions compliant signer that omits References, or truncated/corrupted package parts modified after signing.","solutions":["Re-generate the signature properly with PackageDigitalSignatureManager.Sign so every part is covered by a <Reference> element","Inspect the /_xmlsignatures/*.xml parts in the package and confirm each <SignedInfo> contains at least one <Reference>; fix or remove the corrupt signature part","Remove the invalid signature (PackageDigitalSignatureManager.RemoveSignature) and re-sign the package","Verify the package was not modified after signing; restore it from a known-good copy"],"exampleFix":"// before (corrupt signedInfo emitted manually)\n// <SignedInfo>...no Reference elements...</SignedInfo>\n// after: use the signing API instead of hand-crafted XML\n// using (PackageDigitalSignatureManager dsm = new PackageDigitalSignatureManager(package))\n//     dsm.Sign(partUris); // emits a <Reference> per part","handlingStrategy":"try-catch","validationCode":"using var pkg = Package.Open(path, FileMode.Open, FileAccess.Read);\nvar dsm = new PackageDigitalSignatureManager(pkg);\nforeach (var sigUri in dsm.Signatures)\n{\n    var part = pkg.GetPart(sigUri);\n    using var sr = new StreamReader(part.GetStream());\n    string xml = sr.ReadToEnd();\n    if (!xml.Contains(\"<Reference\")) throw new InvalidDataException(\"Signature part has no Reference elements\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    foreach (var sig in package.GetDigitalSignatures()) Verify(sig);\n}\ncatch (XmlException ex) when (ex.Message.Contains(\"PackageSignatureCorruption\") || ex.Message.Contains(\"PackageSignatureCorruption\"))\n{\n    // treat the package as unsigned; re-sign or reject\n}","preventionTips":["Never hand-edit or post-process _xmlsignatures parts; always sign via PackageDigitalSignatureManager","Re-zip OPC packages with tools that preserve all parts unchanged","Validate signed packages after any automated transformation step"],"tags":["xml","digital-signature","packaging","wpf","xmlparse"],"backgroundTag":"xml-parse-error","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"}