Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException in PdfTrailer.cs #85

Open
Azkarell opened this issue Apr 17, 2019 · 1 comment
Open

NullReferenceException in PdfTrailer.cs #85

Azkarell opened this issue Apr 17, 2019 · 1 comment
Labels
enhancement not repro As a matter of principle we only investigate non-trivial issues that are replicable (VS solution) suggestion Suggestion or feature request

Comments

@Azkarell
Copy link

Hi,
I recently had to write a simple Application to merge some PDFs. In most cases PDFSharp worked like a charm but I had one PDF where PDFReader.Open threw a NullReferenceException.

bei PdfSharp.Pdf.Advanced.PdfTrailer.Finish() in C:\repos\PDFsharp\src\PdfSharp\Pdf.Advanced\PdfTrailer.cs:Zeile 196.
  bei PdfSharp.Pdf.IO.PdfReader.Open(Stream stream, String password, PdfDocumentOpenMode openmode, PdfPasswordProvider passwordProvider) in C:\repos\PDFsharp\src\PdfSharp\Pdf.IO\PdfReader.cs:Zeile 506.
  bei PdfSharp.Pdf.IO.PdfReader.Open(String path, String password, PdfDocumentOpenMode openmode, PdfPasswordProvider provider) in C:\repos\PDFsharp\src\PdfSharp\Pdf.IO\PdfReader.cs:Zeile 216.
  bei PdfSharp.Pdf.IO.PdfReader.Open(String path, PdfDocumentOpenMode openmode) in C:\repos\PDFsharp\src\PdfSharp\Pdf.IO\PdfReader.cs:Zeile 186.

Sadly I can't give you the pdf. But i will try to reproduce the error with other pdfs.

my workaround was:
instead of

  if (iref != null && iref.Value == null)
  {
       iref = _document._irefTable[iref.ObjectID];
       Debug.Assert(iref.Value != null);
       _document._trailer.Elements[Keys.Info] = iref;
  }

i used:

 if (iref != null && iref.Value == null)
 {
    iref = _document._irefTable[iref.ObjectID];
    if(iref != null) { 
         _document._trailer.Elements[Keys.Info] = iref;
    }
 }

but I'm really not sure if that is a good idea :)

@Azkarell
Copy link
Author

I spent some time learning how pdf works and i found that the pdf seems to be broken, because in one obj

/Info 3 0 R

is defined as a reference but the whole pdf does not inculde a

3 0 obj

how to handle such cases is up to you but since most readers can still open it. pdfsharp should in my opinion at least not crash.

@ThomasHoevel ThomasHoevel added enhancement not repro As a matter of principle we only investigate non-trivial issues that are replicable (VS solution) suggestion Suggestion or feature request labels Apr 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement not repro As a matter of principle we only investigate non-trivial issues that are replicable (VS solution) suggestion Suggestion or feature request
Projects
None yet
Development

No branches or pull requests

2 participants