PDFsharp icon indicating copy to clipboard operation
PDFsharp copied to clipboard

Cannot open Adobe Sign doc with unencrypted metadata.

Open mguerrieri opened this issue 2 years ago • 2 comments

PDFSharp 6.0.0-preview-3

Code to reproduce: using var pdfReader = PdfReader.Open("c:\\temp\\test.pdf", PdfDocumentOpenMode.ReadOnly);

Exception: Crypt filter value for PdfDictionary is set but CryptFilterDecodeParms are not initialized correctly.

Stack Trace: at PdfSharp.Pdf.Security.PdfStandardSecurityHandler.GetCryptFilter(PdfDictionary dictionary) at PdfSharp.Pdf.Security.PdfStandardSecurityHandler.DecryptStream(Byte[]& bytes, PdfDictionary dictionary) at PdfSharp.Pdf.Security.PdfStandardSecurityHandler.DecryptDictionary(PdfDictionary dict, Boolean decryptObjectStream) at PdfSharp.Pdf.Security.PdfStandardSecurityHandler.DecryptObject(PdfObject value) at PdfSharp.Pdf.Security.PdfStandardSecurityHandler.DecryptDocument() at PdfSharp.Pdf.IO.PdfReader.Open(Stream stream, String password, PdfDocumentOpenMode openMode, PdfPasswordProvider passwordProvider) at PdfSharp.Pdf.IO.PdfReader.Open(String path, String password, PdfDocumentOpenMode openMode, PdfPasswordProvider provider) at PdfSharp.Pdf.IO.PdfReader.Open(String path, PdfDocumentOpenMode openMode)

I unfortunately cannot provide a sample PDF as the failing documents as all have digital signatures and PII data. But here are the (I believe) relevant properties of the documents:

Header: %PDF-1.7

Encrypt Dictionary: <</P -1324/R 4/StrF/StdCF/CF<</StdCF<</Type/CryptFilter/CFM/AESV2/Length 16/EncryptMetadata false>>>>/Filter/Standard/Length 128/U({some bytes.})/V 4/StmF/StdCF/EncryptMetadata false/O({some bytes...})>>

Metadata:

<</Length 5087/Type/Metadata/Subtype/XML/Filter/Crypt>>stream
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 7.1.0">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Description rdf:about=""
            xmlns:xmp="http://ns.adobe.com/xap/1.0/"
            xmlns:pdf="http://ns.adobe.com/pdf/1.3/"
            xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
            xmlns:dc="http://purl.org/dc/elements/1.1/">
         <xmp:CreatorTool>Acrobat Sign</xmp:CreatorTool>
         <xmp:ModifyDate>2023-07-26T10:05:17-07:00</xmp:ModifyDate>
         <xmp:MetadataDate>2023-07-26T10:05:17-07:00</xmp:MetadataDate>
         <pdf:Producer>Acrobat Sign</pdf:Producer>
         <xmpMM:DocumentID>uuid:82c91cd5-9c7c-29da-5522-ee39f67a036c</xmpMM:DocumentID>
         <xmpMM:InstanceID>uuid:f5b4b1f6-9727-2ee8-56ec-ee39f67a036c</xmpMM:InstanceID>
         <dc:format>application/pdf</dc:format>
      </rdf:Description>
   </rdf:RDF>
</x:xmpmeta>

mguerrieri avatar Aug 02 '23 15:08 mguerrieri

Thanks for the feedback. However, without a sample file it's difficult to find the problem. The function, where the exception is thrown, tries to get the correct crypt filter for a dictionary. According to the exception, there is a crypt filter specified for the dictionary, but obviously the CryptFilterDecodeParms are not present or not in the form PDFsharp expects it. Maybe You can give me some further information about the failing document. If You search for /Filter /Crypt, You should find the crypt filters specified explicitly for a dictionary. PDFsharp expects something like this:

<<
  /DecodeParms
  <<
    /Name /{name of the crypt filter}
    /Type /CryptFilterDecodeParms
  >>
  /Filter /Crypt
  /Length {length of the stream}
>>

With unencrypted metadata, the PdfMetadata dictionary should contain an identity crypt filter:

<<
  /DecodeParms
  <<
    /Name /Identity
    /Type /CryptFilterDecodeParms
  >>
  /Filter /Crypt
  /Length {length of the metadata stream}
  /Subtype /XML
  /Type /Metadata
>>

If You could send me the crypt filters of the document, I can try to further investigate the problem.

martinossendorf avatar Sep 05 '23 11:09 martinossendorf

With PDFsharp Version 6.1.0-preview-1 we fixed some encryption related issues. Please report, if your PDF file can now be read without errors.

martinossendorf avatar Jan 02 '24 11:01 martinossendorf