Skip to content

Fix #389: PDFsharp misreads C2PA manifest stream as external file - #391

Open
wooly905 wants to merge 1 commit into
empira:masterfrom
wooly905:fix/389-c2pa
Open

Fix #389: PDFsharp misreads C2PA manifest stream as external file#391
wooly905 wants to merge 1 commit into
empira:masterfrom
wooly905:fix/389-c2pa

Conversation

@wooly905

@wooly905 wooly905 commented Sep 3, 2026

Copy link
Copy Markdown

Parser.GetStreamLength treated any /F key on a stream dictionary as an external file stream per PDF 2.0 section 7.3.8.2, but some producers (e.g. ChatGPT-generated PDFs) misuse /F for embedded-file params instead of /Params. This caused NotImplementedException when opening such PDFs.

Now only strings, or dictionaries that actually look like a file specification (/Type /Filespec, or one of /FS, /F, /UF, /DOS, /Mac, /Unix), trigger the exception. Genuine external file streams still throw as before.

Adds PdfSharp.Pdf.C2pa.C2paManager / C2paManifestInfo to read C2PA manifests from a document's /AF array and /EmbeddedFiles name tree, plus a PdfAFRelationship.C2paManifest constant. Wired into PdfDocument and the gdi/wpf mirror csproj files.

Adds a duck.pdf test asset and 7 xUnit tests covering the fix, manifest reading, and a guard test confirming real external file streams still throw. Adds a ReadC2paInfo sample app that decodes the manifest's JUMBF/CBOR/COSE structures to independently verify claim, actions, and signature data.

Parser.GetStreamLength treated any /F key on a stream dict as an external file stream per PDF 2.0 7.3.8.2, but some producers (e.g. ChatGPT-generated PDFs) misuse /F for embedded-file params instead of /Params. Now only strings or dictionaries that actually look like a file specification (/Type /Filespec, or /FS,/F,/UF,/DOS,/Mac,/Unix) trigger the NotImplementedException; genuine external file streams still throw.

Adds PdfSharp.Pdf.C2pa.C2paManager/C2paManifestInfo to read C2PA manifests from a document's /AF array and /EmbeddedFiles name tree, plus a PdfAFRelationship.C2paManifest constant. Wired into PdfDocument and the gdi/wpf mirror csprojs.

Adds duck.pdf test asset and 7 xUnit tests covering the fix, manifest reading, and a guard test for real external file streams. Adds a ReadC2paInfo sample app that decodes the manifest's JUMBF/CBOR/COSE structures to verify claim, actions, and signature data end-to-end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant