PDFsharp & MigraDoc Foundation

References to NULL objects
Page 1 of 1

Author:  (void) [ Tue Apr 10, 2018 4:59 pm ]
Post subject:  References to NULL objects

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.

Author:  TH-Soft [ Fri Apr 13, 2018 6:35 am ]
Post subject:  Re: References to NULL objects


Thanks for the feedback, code change looks good.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group