From d6337ee3a2c5103e1c96642792c95ac33b336b9f Mon Sep 17 00:00:00 2001 From: Matthew Laukala Date: Tue, 14 Nov 2017 10:10:51 -0800 Subject: [PATCH] IsValidXref() no will no longer check if it's inside of a stream beyong an EOF symbol. --- src/PdfSharp/Pdf.IO/Parser.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/PdfSharp/Pdf.IO/Parser.cs b/src/PdfSharp/Pdf.IO/Parser.cs index bd21277b..95a9b11e 100644 --- a/src/PdfSharp/Pdf.IO/Parser.cs +++ b/src/PdfSharp/Pdf.IO/Parser.cs @@ -1088,17 +1088,21 @@ private bool IsValidXref() content += _lexer.ReadRawString(content_pos, read_length); int ss = content.IndexOf("stream", StringComparison.Ordinal); + int eof = content.IndexOf("%%EOF", StringComparison.Ordinal); int es = content.IndexOf("endstream", StringComparison.Ordinal); - if (ss < es) - { - // Not inside of stream - break; - } - else if (es != -1 && ss > es) + int s = Math.Min(ss, eof); + + if (s != es) { - // inside of stream - return false; + if (s == -1) + return false; + else if (es == -1) + break; + else if (s < es) + break; + else if (s > es) + return false; } content_pos = content_pos + read_length;