PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Dec 03, 2021 1:00 pm

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Apr 10, 2018 4:59 pm 

Joined: Tue Sep 30, 2014 12:29 pm
Posts: 26
I just came across a document that contained the following :
9 0 obj
<</Size 26/Root 3 0 R/Info 9 0 R>>

As one can see, the /Info entry in the trailer is a reference to a null-object.
When loading the document with PdfSharp, this results in an assertion in debug mode ("Bug in PdfSharp. Send this document...") and a crash in release mode:

Unhandled Exception: System.InvalidCastException: Unable to cast object of type 'PdfSharp.Pdf.PdfNullObject' to type 'PdfSharp.Pdf.PdfDictionary'.
at PdfSharp.Pdf.PdfDictionary.DictionaryElements.GetValue(String key, VCF options)
at PdfSharp.Pdf.PdfDocument.get_Info()
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)

Digging into this, i was able to fix this with the following changes:
In PdfDictionary.GetValue(String key, VCF options), change the first if-statement from
if (value == null)

if (value == null || value is PdfNull || (value is PdfReference && ((PdfReference)value).Value is PdfNullObject))

thus treating a reference to a null-object like null.

If this may lead to regressions for some reason, please let me know.

Reply with quote  
PostPosted: Fri Apr 13, 2018 6:35 am 
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 683
Location: CCAA

Thanks for the feedback, code change looks good.

Best regards
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group