PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Jul 20, 2018 6:44 am

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 
Offline

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

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
Code:
if (value == null)

to
Code:
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.


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 13, 2018 6:35 am 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 381
Location: CCAA
Hi!

Thanks for the feedback, code change looks good.

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


Top
 Profile  
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 1 guest


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