diff --git a/src/PdfSharp/Pdf.IO/Parser.cs b/src/PdfSharp/Pdf.IO/Parser.cs index ebaa6b0b..7334dd2f 100644 --- a/src/PdfSharp/Pdf.IO/Parser.cs +++ b/src/PdfSharp/Pdf.IO/Parser.cs @@ -1107,14 +1107,17 @@ 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) + int s = Math.Min(ss, eof); + + if (s < es) { // Not inside of stream break; } - else if (ss > es) + else if (s > es) { // inside of stream return false;