From c8b42f4fd4bf8a63ecda3d51861e71f4d30fd56b Mon Sep 17 00:00:00 2001 From: Zach Langner Date: Fri, 11 Mar 2022 11:44:08 -0600 Subject: [PATCH] Fixed null ref exception in PdfDocumentBuilder Fixed null ref exception in PdfDocumentBuilder that occurs when TokenScanner returns null for the IndirectReferenceToken provided. --- src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs b/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs index a50b3870..039223bf 100644 --- a/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs +++ b/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs @@ -400,7 +400,13 @@ namespace UglyToad.PdfPig.Writer var val = kvp.Value; if (kvp.Value is IndirectReferenceToken ir) { - val = document.Structure.TokenScanner.Get(ir.Data).Data; + ObjectToken tk = document.Structure.TokenScanner.Get(ir.Data); + if (tk == null) + { + // malformed + continue; + } + val = tk.Data; } if (!(val is ArrayToken arr))